CodeIgniter Forums
Expired cache files are not cleared - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Expired cache files are not cleared (/showthread.php?tid=79105)



Expired cache files are not cleared - AngelRodriguez - 04-20-2021

Hi,

I have a problem, expired cache files are not cleared.

Saving cache like (this for example) version CI 4.1.1

PHP Code:
if (! $foo cache('foo'))
{
    echo 'Saving to the cache!<br />';
    $foo 'foobarbaz!';

    // Save into the cache for 5 minutes
    cache()->save('foo'$foo300);
}

echo 
$foo



Files are supposed to delete themselves, right?

Or do I have to do something manually to delete them?

Thank you

Ángel


RE: Expired cache files are not cleared - InsiteFX - 04-20-2021

If they do not delete you can do it yourself like so.

PHP Code:
$cache = \Config\Services::cache();

// your cache item id.
$this->cache->delete('cache_item_id');

// clean the cache out.
$this->cache->clean();

// get the cache information.
var_dump($this->cache->cache_info()); 



RE: Expired cache files are not cleared - lucascortes - 12-09-2023

Get the entire cache and loop one by one, so if it is expired it will return NULL and delete the file.

Code:
$allDataCache = $this->cache->getCacheInfo();
foreach ($allDataCache as $key => $value) {
   $this->cache->get($key);
}