Part of the EllisLab Network
x
 
Create New Page
 View Previous Changes    ( Last updated by beemr )

No Flash Cache

Modify the Output class’ function _write_cache() to prevent your flashdata from getting stuck in a cache file.  Save as system/application/libraries/MY_Output.php.

Lines added:

// Na-ah-ah! no flashing allowed in the cache;
        
$userdata $CI->session->all_userdata();
        foreach (
$userdata as $k => $v)
            
{
                
if (strpos($k,'flash:') !== FALSE) return;
            


MY_Output

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

/**
 * No Flash Cache
 *
 * @package        CodeIgniter
 * @subpackage    Libraries
 * @hacked-by    Bradford Mar
 */
class MY_Output extends CI_Output {
    
    
/**
     * Write a Cache File
     *
     * @access    public
     * @return    void
     */    
    
function _write_cache($output)
    
{
        $CI 
=& get_instance();

    
// Na-ah-ah! no flashing allowed in the cache;
        
$userdata $CI->session->all_userdata();
        foreach (
$userdata as $k => $v)
            
{
                
if (strpos($k,'flash:') !== FALSE) return;
            
}

        $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').
                
$CI->uri->uri_string();
        
        
$cache_path .= md5($uri);

        if ( ! 
$fp = @fopen($cache_path'wb'))
        
{
            log_message
('error'"Unable to write cache file: ".$cache_path);
            return;
        
}
        
        $expire 
time() + ($this->cache_expiration 60);
        
        
flock($fpLOCK_EX);
        
fwrite($fp$expire.'TS--->'.$output);
        
flock($fpLOCK_UN);
        
fclose($fp);
        @
chmod($cache_pathDIR_WRITE_MODE);

        
log_message('debug'"Cache file written: ".$cache_path);
    
}