CodeIgniter Forums
Caching - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Caching (/showthread.php?tid=15852)



Caching - El Forum - 02-16-2009

[eluser]Michael Nielsen[/eluser]
I'm currently using the CI cache class however when I update information in my database it takes 30 seconds to take visual affect.

Is it possible to have the cache file re-written when I update my database so my users get to see their changes immediately?


Caching - El Forum - 02-16-2009

[eluser]sophistry[/eluser]
you have to delete the cache file manually.
http://ellislab.com/codeigniter/user-guide/general/caching.html


Caching - El Forum - 02-16-2009

[eluser]Michael Nielsen[/eluser]
yes i know that but I want it do be done when the user updates their information, My question was is it possible?


Caching - El Forum - 02-16-2009

[eluser]sophistry[/eluser]
there is no CI 'interface' for deleting cache files. that is why i said do it manually.

this php function deletes files...
Code:
unlink();



Caching - El Forum - 02-16-2009

[eluser]fesweb[/eluser]
And to find the correct file to delete, I believe you do something like this
Code:
$file_to_delete = md5($the_uri_of_the_page);



Caching - El Forum - 07-16-2010

[eluser]minerbog[/eluser]
I have written a extension of the output class to do just this. Be aware that the cache system creates a md5 hash of the whole uri to use as a file name. This includes the 3rd 4th 5th etc segments, so i suggest anyone using this code uses it only with say test controller and some function like index.php/test/some.

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Output extends CI_Output {
    
    function delete_page_cache($segment_one = '')
    {
        $CI =& get_instance();    
        $path = $CI->config->item('cache_path');
    
        $cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
        
        if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
        {
            return;
        }
        
        $uri =    $CI->config->item('base_url').
                $CI->config->item('index_page').
                '/'.$segment_one;
        
        $cache_path .= md5($uri);
        
        unlink($cache_path);
    }
    
}

useage : $this->output->delete_page_cache('test/some');

Hope someone finds this useful.

Gavin.