|
9 | 9 | - [Storing Items In The Cache](#storing-items-in-the-cache) |
10 | 10 | - [Removing Items From The Cache](#removing-items-from-the-cache) |
11 | 11 | - [The Cache Helper](#the-cache-helper) |
12 | | -- [Cache Tags](#cache-tags) |
13 | | - - [Storing Tagged Cache Items](#storing-tagged-cache-items) |
14 | | - - [Accessing Tagged Cache Items](#accessing-tagged-cache-items) |
15 | | - - [Removing Tagged Cache Items](#removing-tagged-cache-items) |
16 | | - - [Pruning Stale Cache Tags](#pruning-stale-cache-tags) |
17 | 12 | - [Atomic Locks](#atomic-locks) |
18 | 13 | - [Driver Prerequisites](#lock-driver-prerequisites) |
19 | 14 | - [Managing Locks](#managing-locks) |
@@ -267,51 +262,6 @@ When the `cache` function is called without any arguments, it returns an instanc |
267 | 262 | > **Note** |
268 | 263 | > When testing call to the global `cache` function, you may use the `Cache::shouldReceive` method just as if you were [testing the facade](/docs/{{version}}/mocking#mocking-facades). |
269 | 264 |
|
270 | | -<a name="cache-tags"></a> |
271 | | -## Cache Tags |
272 | | - |
273 | | -> **Warning** |
274 | | -> Cache tags are not supported when using the `file`, `dynamodb`, or `database` cache drivers. Furthermore, when using multiple tags with caches that are stored "forever", performance will be best with a driver such as `memcached`, which automatically purges stale records. |
275 | | -
|
276 | | -<a name="storing-tagged-cache-items"></a> |
277 | | -### Storing Tagged Cache Items |
278 | | - |
279 | | -Cache tags allow you to tag related items in the cache and then flush all cached values that have been assigned a given tag. You may access a tagged cache by passing in an ordered array of tag names. For example, let's access a tagged cache and `put` a value into the cache: |
280 | | - |
281 | | - Cache::tags(['people', 'artists'])->put('John', $john, $seconds); |
282 | | - |
283 | | - Cache::tags(['people', 'authors'])->put('Anne', $anne, $seconds); |
284 | | - |
285 | | -<a name="accessing-tagged-cache-items"></a> |
286 | | -### Accessing Tagged Cache Items |
287 | | - |
288 | | -Items stored via tags may not be accessed without also providing the tags that were used to store the value. To retrieve a tagged cache item, pass the same ordered list of tags to the `tags` method and then call the `get` method with the key you wish to retrieve: |
289 | | - |
290 | | - $john = Cache::tags(['people', 'artists'])->get('John'); |
291 | | - |
292 | | - $anne = Cache::tags(['people', 'authors'])->get('Anne'); |
293 | | - |
294 | | -<a name="removing-tagged-cache-items"></a> |
295 | | -### Removing Tagged Cache Items |
296 | | - |
297 | | -You may flush all items that are assigned a tag or list of tags. For example, this statement would remove all caches tagged with either `people`, `authors`, or both. So, both `Anne` and `John` would be removed from the cache: |
298 | | - |
299 | | - Cache::tags(['people', 'authors'])->flush(); |
300 | | - |
301 | | -In contrast, this statement would remove only cached values tagged with `authors`, so `Anne` would be removed, but not `John`: |
302 | | - |
303 | | - Cache::tags('authors')->flush(); |
304 | | - |
305 | | -<a name="pruning-stale-cache-tags"></a> |
306 | | -### Pruning Stale Cache Tags |
307 | | - |
308 | | -> **Warning** |
309 | | -> Pruning stale cache tags is only necessary when using Redis as your application's cache driver. |
310 | | -
|
311 | | -In order to properly prune stale cache tag entries when using the Redis cache driver, Laravel's `cache:prune-stale-tags` Artisan command should be [scheduled](/docs/{{version}}/scheduling) in your application's `App\Console\Kernel` class: |
312 | | - |
313 | | - $schedule->command('cache:prune-stale-tags')->hourly(); |
314 | | - |
315 | 265 | <a name="atomic-locks"></a> |
316 | 266 | ## Atomic Locks |
317 | 267 |
|
|
0 commit comments