Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 Cache Tags not working

I am using Laravel 5.2 Cache with memcached driver.

Was trying to implement the Cache::tags into my project but doesn't seems to be working.

But it works well when I am using

Cache::put('user_1', $user, 600);

Here is my code

Cache::tags('user')->put('user_1', $user, 600);

and I've tried using

Cache::tags(['user'])->put('user_1', $user, 600);

as it mentioned in the API docs saying it supported array|mixed $names

Not sure if anyone out there having the similar issue like me?

like image 1000
Keith Yeoh Avatar asked Oct 19 '22 12:10

Keith Yeoh


1 Answers

This got me quite confused as well. When using cache tags with Laravel, to fetch the stored data from the cache, you need to specify the used tag(s).

E.g. when storing data like this:

Cache::tags('user')->put('user_1', $user, 600);

This won't fetch the data back:

Cache::get('user_1');

But this will:

Cache::tags('user')->get('user_1');

The behaviour is still the same with Laravel 5.4 (current version at the time of writing).

like image 115
osteel Avatar answered Nov 15 '22 06:11

osteel