Welcome Guest, Not a member yet? Register   Sign In
Caching
#1

[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?
#2

[eluser]sophistry[/eluser]
you have to delete the cache file manually.
http://ellislab.com/codeigniter/user-gui...ching.html
#3

[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?
#4

[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();
#5

[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);
#6

[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.




Theme © iAndrew 2016 - Forum software by © MyBB