how to purge expired cache files? |
I'm hoping to cache some search results like so:
Code: $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file')); In this case, $some_cache_id could be nearly anything because this id is derived from the search terms entered by the user. If a subsequent user enters the same search, I need to be able to call up those search results so the id must be derived from the user search terms. This introduces a challenge because users can search for pretty much any number of different search strings. This is likely to result in a LOT of cache files being generated. I'm concerned that this may rapidly chew up limited hard drive space on this cloud-hosted server -- I have in fact seen this exact situation occur on another project. I've been scouring CodeIgniter's system files and it would appear that expired cache files are *only* purged if there is another request for the exact same cache id. This is implemented in the get() function in system/libraries/Cache/drivers/Cache_file.php: Code: /** Is there some recommended way to make sure expired cache files get purged periodically? Perhaps the CI devs might consider implementing a probabilistic garbage collection method for purging expired cache files like PHP's session.gc_probability? Or perhaps some way to limit the cache size? Can anyone suggest a way that I might implement a purge myself?
@sneakyimp,
What about simply deleting the cache... https://codeigniter.com/user_guide/gener...ing-caches (09-12-2018, 01:27 PM)php_rocs Wrote: @sneakyimp, That will not work. I need the other files in the cache! They're cached for a reason.
If your hosts support it you can setup an automatic process to purge expired cache files on a regular basis. Note: Cache is switched off by default. To enable the cache for your site see help25ite Global configuration
|
Welcome Guest, Not a member yet? Register Sign In |