Welcome Guest, Not a member yet? Register   Sign In
manual clear page caching code
#1

[eluser]ifew[/eluser]
i'm create some easy method for clear page caching by extend from CI_Output


1. create file in System/Application/Library

/system/application/libraries/My_Output.php ("My_" is your library suffix name)

2. extend from CI_Output

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

    /**
    * Clear Cache
    *
    * Responsible for sending final output to browser
    *
    * @package        CodeIgniter
    * @subpackage    Libraries
    * @added-by    Chitpong Wuttanan (http://lab.tosdn.com)
    */
    class My_Output extends CI_Output {

        function clear_cache($set_uri = NULL){
            $CFG =& load_class('Config');
            $filepath = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path').md5($set_uri);

            if(file_exists($filepath)) {
                @unlink($filepath);
                log_message('debug', "Cache deleted for: ".$set_uri);
            } else {
                return FALSE;
            }
        }
    }

    ?>

3. how to use page caching

Code:
$this->output->cache(60); //1 Hour
$this->load->view('profile.php');

4. how to clear page caching

Code:
$this->output->clear_cache('http://www.web.com/profile');
// "http://www.web.com/profile" is URI page for clearing

Reference Page Caching with CodeIgniter and Cache Clearing code
#2

[eluser]DominixZ[/eluser]
I suggest another good function. It is clear_all_cache();

This may be nice when use in backend.
#3

[eluser]ifew[/eluser]
this function good for clear some page Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB