Search code examples
laravelcachinglaravel-8

Laravel cache expire sooner than its ttl when using file driver


When I use file file driver for cache, the cache file gets created and accessible, but for about only 1 minutes. it seems ttl parameter has no affect.

Route::get('setCache', function () {
    Cache::store('file')->put('testCache1', 'testCache1 value', now()->addHours(12));
});
Route::get('getCache', function () {
    dd(Cache::store('file')->get('testCache1'));
});

After visiting /setCache cache file get created, and I can see the cached value in /getCache path. but after about a minute or less, the /getCache shows null and the cached file gets deleted.
the above code works correct when I use database driver.
since the cache get created and accessible for a short time, I don't think it's related to permissions.


Solution

  • The informations are not enough, you must have clearing the cache somewhere else in your application. but make sure you dont use Cache::flush anywhere in your all Laravel applications in your machine, it doesn't respect the 'prefix', see the doc.