bcs02123052's avatar

how to get all cache items by tag ?

Is there a way to get all the cache items by tag maybe like this

// save the items in cache

 $banks = Bank::all();
foreach ($banks as $bank) {
		Cache::tags(['banks'])->put('bank_' . $bank->id, $bank, now()->addHours(1000));
}

// the get items like this maybe

$banks = Cache::tags("banks")->getAll();
1 like
6 replies
bcs02123052's avatar

in laravel doc example we have to know the key like user-1 the laravel will look for user-1 with tags banks

what I want is to get all the items without specifying the user-1 @vincent15000

1 like
tobz.nz's avatar

I know this is an old thread, but thought I'd post this anyway - a Macro that does as you'd expect:

You can then get all the items with any combination of tags.

Cache::tags(['tag1', 'tag2', 'tag3'])->put('item1', 1);
Cache::tags(['tag1', 'tag4'])->put('item1', 2);
Cache::tags(['tag1', 'tag3'])->put('item1', 3);

Cache::tags(['tag1', 'tag2', 'tag3'])->getAll();
// item 1

Cache::tags(['tag1'])->getAll();
// item1, item 2, item 3

Cache::tags(['tag3'])->getAll();
// item 1, item 3
2 likes

Please or to participate in this conversation.