CodeIgniter Forums
$this->db->cache_delete('controller', '*'); - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: $this->db->cache_delete('controller', '*'); (/thread-14404.html)



$this->db->cache_delete('controller', '*'); - El Forum - 01-01-2009

[eluser]jstrebel[/eluser]
Will the cache_delete function accept a wildcard *, or at least a regular expression of some sort?

I would like to delete all the caches files created from 1 controller, but not every cache from all controllers... as delete_all() would.

IN this case the 2nd uri segment is remapped to one of hundreds of tag names, like /ideas/bar /ideas/foo

Thanks.


$this->db->cache_delete('controller', '*'); - El Forum - 01-01-2009

[eluser]jstrebel[/eluser]
anyone?


$this->db->cache_delete('controller', '*'); - El Forum - 01-02-2009

[eluser]Pascal Kriete[/eluser]
It doesn't currently accept anything of the sort, but it shouldn't be too hard to write a helper that does it.

Something along these lines. Untested (so be careful!):
Code:
// Cache files are stored as segment1+segment2, so construct your pattern accordingly
function regex_purge_db_cache($pattern)
{    
    $CI =& get_instance();
    $CI->load->helper('file');
    
    $pattern = $CI->db->cachedir.$pattern;
    
    $paths = glob($pattern, GLOB_ONLYDIR|GLOB_NOSORT|GLOB_MARK);
    
    foreach($paths as $path)
    {
        delete_files($path, TRUE);
    }
}