Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PetroGromovo's avatar

How better to clear cache in redis for posts which are not updated very often ?

On laravel 10 site I have several types of data which I want to save in redis. Different data have different time when data are expired. I think I can do it in 2 ways : // Store a value in the Redis cache with minutes set :

Cache::put('Post_Key', 'PostContent', 60 * 24 * 30); // Cache for 1 month

OR using Cache::foreve method with manuall clearing cache data of the app running scheduled tasks(if I need to refresh all cache) or say if post is updated in admin panel to clear 'Post_Key' - so next calling it would be refreshed...

In .env file I have to keep

CACHE_DRIVER=redis

to use redis

I wonder which way (or some other) is preferable from the point of performance and stable work of the app ?

"laravel/framework": "^10.48.7",
"predis/predis": "^2.2",

Thanks in advance!

0 likes
1 reply
JussiMannisto's avatar

Month vs. forever is not going to make any difference from a performance point of view. Just make sure you invalidate the cache entry whenever a post is updated.

If you want to speed up Redis, install and use the PhpRedis extension instead of the Predis package. PhpRedis is written in C and is many times faster than Predis. But honestly, you probably won't notice a difference unless you're hitting the cache a lot.

1 like

Please or to participate in this conversation.