Skip to content

Commit b801c12

Browse files
Use fenced code blocks (#10850)
1 parent 0714aa1 commit b801c12

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

cache.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,30 +410,38 @@ cache()->remember('users', $seconds, function () {
410410

411411
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:
412412

413-
use Illuminate\Support\Facades\Cache;
413+
```php
414+
use Illuminate\Support\Facades\Cache;
414415

415-
Cache::tags(['people', 'artists'])->put('John', $john, $seconds);
416-
Cache::tags(['people', 'authors'])->put('Anne', $anne, $seconds);
416+
Cache::tags(['people', 'artists'])->put('John', $john, $seconds);
417+
Cache::tags(['people', 'authors'])->put('Anne', $anne, $seconds);
418+
```
417419

418420
<a name="accessing-tagged-cache-items"></a>
419421
### Accessing Tagged Cache Items
420422

421423
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, then call the `get` method with the key you wish to retrieve:
422424

423-
$john = Cache::tags(['people', 'artists'])->get('John');
425+
```php
426+
$john = Cache::tags(['people', 'artists'])->get('John');
424427

425-
$anne = Cache::tags(['people', 'authors'])->get('Anne');
428+
$anne = Cache::tags(['people', 'authors'])->get('Anne');
429+
```
426430

427431
<a name="removing-tagged-cache-items"></a>
428432
### Removing Tagged Cache Items
429433

430434
You may flush all items that are assigned a tag or list of tags. For example, the following code would remove all caches tagged with either `people`, `authors`, or both. So, both `Anne` and `John` would be removed from the cache:
431435

432-
Cache::tags(['people', 'authors'])->flush();
436+
```php
437+
Cache::tags(['people', 'authors'])->flush();
438+
```
433439

434440
In contrast, the code below would remove only cached values tagged with `authors`, so `Anne` would be removed, but not `John`:
435441

436-
Cache::tags('authors')->flush();
442+
```php
443+
Cache::tags('authors')->flush();
444+
```
437445

438446
<a name="atomic-locks"></a>
439447
## Atomic Locks

0 commit comments

Comments
 (0)