From 2e1ba63b2d0112b095557e038576c02cfebea66a Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Wed, 8 Oct 2025 17:58:01 +0300 Subject: [PATCH] Use fenced code blocks --- cache.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cache.md b/cache.md index 5fff679ee6..a1a8975c89 100644 --- a/cache.md +++ b/cache.md @@ -410,30 +410,38 @@ cache()->remember('users', $seconds, function () { 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: - use Illuminate\Support\Facades\Cache; +```php +use Illuminate\Support\Facades\Cache; - Cache::tags(['people', 'artists'])->put('John', $john, $seconds); - Cache::tags(['people', 'authors'])->put('Anne', $anne, $seconds); +Cache::tags(['people', 'artists'])->put('John', $john, $seconds); +Cache::tags(['people', 'authors'])->put('Anne', $anne, $seconds); +``` ### Accessing Tagged Cache Items 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: - $john = Cache::tags(['people', 'artists'])->get('John'); +```php +$john = Cache::tags(['people', 'artists'])->get('John'); - $anne = Cache::tags(['people', 'authors'])->get('Anne'); +$anne = Cache::tags(['people', 'authors'])->get('Anne'); +``` ### Removing Tagged Cache Items 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: - Cache::tags(['people', 'authors'])->flush(); +```php +Cache::tags(['people', 'authors'])->flush(); +``` In contrast, the code below would remove only cached values tagged with `authors`, so `Anne` would be removed, but not `John`: - Cache::tags('authors')->flush(); +```php +Cache::tags('authors')->flush(); +``` ## Atomic Locks