Isn't it cleared if you give a time, i.e.,
Cache::put('key', 'value', now()->addMinutes(10));
Seems you could write an artisan command for other cache.
Anyone knows when and how Laravel prunes it's storage\framework\cache folder? i.e. delete cache entries that have expired.
I'm trying to locate the code to understand their caching mechanism. Thank you.
Short answer: it doesn't.
At least not for the file driver. I also think that not for the database driver either.
Actually for the driver it works, the underlying engine takes care of it (such as DynamoDB, Memcached, etc.).
There is an Artisan command to clear all cached data, but not for pruning only expired data.
I guess the philosophy is that when you try to access an expired key it will refresh its content.
But that is a problem when one's app relies on dynamic generated cache keys that doesn't get hit after some time. For example caching blog posts using by their ids. If you use the file or database cache drivers, they will grow, and grow, and without pruning expired keys the disk space will still be used after expiration.
There are some packages that add this ability, one example that adds pruning for the file cache driver is:
https://github.com/arifhp86/laravel-clear-expired-cache-file
There are reports of issues due to lack of expired cache pruning, one from Laravel's issue tracker is:
Please or to participate in this conversation.