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

uniqueginun's avatar

what happens to cache files when ttl passes?

Hello everyone,

when I cache something in Laravel using Cache Facade let's say for one hour ttl, what happen to the file created after this hour? will it be deleted automatically?

0 likes
8 replies
bugsysha's avatar

Are you referring to a file that is created to cache the value when using file cache driver? It will be updated, but technically it uses the same approach as Redis. You can look it up and read more about it.

Snapey's avatar

stale cache files are deleted I think the same as sessions, but anyway if you have a value stored in cache and it expires, I think it will sit there until you try to access the value and then it will be overwritten by a new copy

Why do you ask, and what cache driver are you using?

uniqueginun's avatar

@Snapey I'm using file driver. I'm using cache to cache some huge queries and I use the session id + auth id as the key and I'm wondering when the user logs out what will happen for the previous cached data.

Snapey's avatar

@uniqueginun ok so basically, your choice of key will mean that the cache stays until you actively clear it with artisan cache:clear. I think I would have a cron job that runs at a quiet time and clears the cache daily.

ArturHanusek's avatar

It might be an old post but I just came across issue related to this.

Cache:get() will leave the files on the server until you delete them. Cache:pull() will delete the file after read

I'm using cache to monitor jobs starting / finishing, each tile job starts, I save start time and few other details to cache. This creates many read/writes as job volume is quite high. Every few months our server disk would get filled upto the reams, which was strange because we don't have any file operations. Everything is saved in DB. Turns out, that this micro cache files stay on server and can fill up 20gb once every few months...

Use Cache:pull() to be safe!

Please or to participate in this conversation.