2

I am using using laravel and Redis driver to store my cache and I keep my keys scoped to the current tenant. Below is how I set my cache; where $tenant is the current tenant.

$department_count = Cache::remember('dep_count:'.$tenant, 60 * 60 * 24, function () use ($tenant) {
       return Department::where('is_active', 'yes')->where('tenantID', $tenant)->count();
});

So on switch school, I want to clear all the cache for current tenant using cache::forget() but I don't know how to do that.

I've tried Cache::forget('*:'.$tenant) but it doesn't seem to work. Any help on how to go about it is much appreciated.

1 Answer 1

2

If you want group cache and remove only specific group of cache you can use tags.

Please read this. It will be helpful

Cache::tags(['tag_'.$tenant])->remember('dep_count:'.$tenant, 60 * 60 * 24, function () use ($tenant) {
       return Department::where('is_active', 'yes')->where('tenantID', $tenant)->count();
});

For remove

Cache::tags(['tag_'.$tenant])->flush();
Sign up to request clarification or add additional context in comments.

1 Comment

This will work for me, I didn't know about tags. Thank you very much @Aro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.