0

I have this code :

\Cache::tags(['test'])->put('a', 1);
\Cache::tags(['test'])->put('b', 2);

now I want to get all keys which are stored in cache in 'test' tag, something like this :

print_r(\Cache::tags(['test'])->getAllKeys());

with this output :

a
b

any idea?

fico7489
  • 7,931
  • 7
  • 55
  • 89
  • I don't think that is possible, it depends on the cache driver. Why do you need these? This might be [an xy problem](http://xyproblem.info/). – Jerodev Jul 19 '18 at 14:04
  • thanks for answer, I have in mind some alternatives and workarounds for my problem, I just asked if something like this is possible... – fico7489 Jul 19 '18 at 14:07
  • Answered it here https://stackoverflow.com/questions/26340011/laravel-cache-get-all-items-with-tag/75070859#75070859 – Max Flex Jan 10 '23 at 14:45

1 Answers1

1

This isn't possible through Laravel's Cache system as of writing this.

Laravel's Cache Store contract can be found at https://laravel.com/api/5.6/Illuminate/Contracts/Cache/Store.html

For cache implementations, the only contracted methods to retrieve items from the cache are get() and many(), both of which require you to specify the exact keys of the items you wish to retrieve.

Certain stores, like memcached, extend the TaggableStore, but this only has the one method to tag items.

That's not to say you couldn't query your memcached independently of the cache methods, or write your own Store implementation with additional methods.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95