The Cache class in laravel has methods such as get('itemKey') to retrieve items from the cache, and remember('itemKey', ['myData1', 'myData2']) to save items in the cache.
There is also a method to check if an item exists in the cache: Cache::has('myKey');
Is there any way, (when using the file-based cache driver), to get a list of all items in the cache?
For instance, something that might be named something like "Cache::all()" that would return:
[
'itemKey' => [
'myData1',
'myData2'
],
'myKey' => 'foo'
]
The only way I can think of doing this is to loop through all possible key names using the Cache::has() method. i.e. aaa, aab, aac, aad... but of course, this is not a solution.
I can't see anything in the documentation or the API that describes a function like this, but I don't think its unreasonable to believe that one must exist.
Show activity on this post. The Cache class in laravel has methods such as get ('itemKey') to retrieve items from the cache, and remember ('itemKey', ['myData1', 'myData2']) to save items in the cache. There is also a method to check if an item exists in the cache: Cache::has ('myKey');
The underlaying Cache Drive is not supported retrieve all caches of a certain tag. If u really need this kind of feature, u should looking for Redis, using Redis' hash instead of Cache's tags.
The cached data is usually stored in a very fast data store such as Memcached or Redis. Thankfully, Laravel provides an expressive, unified API for various cache backends, allowing you to take advantage of their blazing fast data retrieval and speed up your web application. Your application's cache configuration file is located at config/cache.php.
If you’ve set up your Laravel application with Redis and you want to see all the keys registered in your Redis, simply open Laravel Tinker using the following command: And then run the following code snippet to get all the keys available in your redis:
Older answers didn't work for me in Laravel 5.2 so I used this solution:
$storage = \Cache::getStore(); // will return instance of FileStore
$filesystem = $storage->getFilesystem(); // will return instance of Filesystem
$dir = (\Cache::getDirectory());
$keys = [];
foreach ($filesystem->allFiles($dir) as $file1) {
if (is_dir($file1->getPath())) {
foreach ($filesystem->allFiles($file1->getPath()) as $file2) {
$keys = array_merge($keys, [$file2->getRealpath() => unserialize(substr(\File::get($file2->getRealpath()), 10))]);
}
}
else {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With