Reputation: 419
In my Laravel application, I have multiple cache stores, all using Redis, defined like so:
// config/cache.php
'stores' => [
...
'geo-index' => [
'driver' => 'redis',
],
'batches' => [
'driver' => 'redis',
],
...
],
Which does work... kinda...
If I look inside Redis KEYS *
, I do get everything stored, however, I can't distinguish which value is in which store (by looking at key prefix), also, more importantly, no matter how I clear one store:
# like so
php artisan cache:clear <store>
#or so
cache()->store($store)->clear();
all stores get cleared, and Redis KEYS *
returns an empty array.
I need this in order to be able to clear one set of data while keeping others.
Am I using this wrongly? or am I missing something here?
Upvotes: 0
Views: 1524
Reputation: 360
As all of your Cache stores are using Redis, when you use clear() or flush() it will clear all Redis cache. Instead, you can define a single Redis cache in stores array and use Tags to group your cache and remove them at your convenience. For example to store items in geo-index, use:
Cache::store('redis')->tags(['geo-index'])->put('foo', 'bar');
to remove all cache tagged as geo-index, use:
Cache::store('redis')->tags(['geo-index'])->flush();
Upvotes: 1