Welcome Guest, Not a member yet? Register   Sign In
Caching and headers
#67

[eluser]Arjen van Bochoven[/eluser]
Ok, with CI 1.7.0 the above fix is broken. The format of $this->header array has changed.

I also need header caching, so I used serialize() to store the header data. This will make you less dependent on the internal storage mechanism of the headers. I also separated the expiration string. In practice it looks like this:

in _write_cache() I replaced

Code:
fwrite($fp, $expire.'TS--->'.$output);

with

Code:
fwrite($fp, serialize( array( 'exp' => $expire, 'headers' => $this->headers, 'output' => $output)));

and in _display_cache(), I replaced

Code:
// Strip out the embedded timestamp        
if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
{
    return FALSE;
}

// Has the file expired? If so we'll delete it.
if (time() >= trim(str_replace('TS--->', '', $match['1'])))
{        
    @unlink($filepath);
    log_message('debug', "Cache file has expired. File deleted");
    return FALSE;
}

// Display the cache
$this->_display(str_replace($match['0'], '', $cache));

with

Code:
// Restore the cache array
$cache = unserialize($cache);

// Validate cache file
if ( ! isset($cache['exp'] ) OR ! isset($cache['headers']) OR ! isset($cache['output']))
{
    return FALSE;
}

// Has the file expired? If so we'll delete it.
if (time() >= trim($cache['exp']))
{        
    @unlink($filepath);
    log_message('debug', "Cache file has expired. File deleted");
    return FALSE;
}

// Restore headers
$this->headers = $cache['headers'];
        
// Display the cache
$this->_display($cache['output']);


Messages In This Thread
Caching and headers - by El Forum - 07-10-2008, 11:38 PM
Caching and headers - by El Forum - 07-11-2008, 05:16 AM
Caching and headers - by El Forum - 07-11-2008, 09:07 AM
Caching and headers - by El Forum - 07-11-2008, 11:34 AM
Caching and headers - by El Forum - 07-11-2008, 12:58 PM
Caching and headers - by El Forum - 07-11-2008, 03:08 PM
Caching and headers - by El Forum - 07-11-2008, 10:38 PM
Caching and headers - by El Forum - 07-11-2008, 10:44 PM
Caching and headers - by El Forum - 07-12-2008, 12:17 AM
Caching and headers - by El Forum - 07-12-2008, 12:21 AM
Caching and headers - by El Forum - 07-12-2008, 12:44 PM
Caching and headers - by El Forum - 07-20-2008, 10:00 PM
Caching and headers - by El Forum - 07-20-2008, 10:30 PM
Caching and headers - by El Forum - 07-20-2008, 10:31 PM
Caching and headers - by El Forum - 07-20-2008, 11:52 PM
Caching and headers - by El Forum - 07-20-2008, 11:54 PM
Caching and headers - by El Forum - 07-21-2008, 05:25 AM
Caching and headers - by El Forum - 07-21-2008, 10:07 AM
Caching and headers - by El Forum - 07-21-2008, 11:47 AM
Caching and headers - by El Forum - 07-21-2008, 03:19 PM
Caching and headers - by El Forum - 07-21-2008, 03:58 PM
Caching and headers - by El Forum - 07-21-2008, 04:21 PM
Caching and headers - by El Forum - 07-21-2008, 05:31 PM
Caching and headers - by El Forum - 07-21-2008, 06:46 PM
Caching and headers - by El Forum - 07-21-2008, 07:02 PM
Caching and headers - by El Forum - 07-21-2008, 07:11 PM
Caching and headers - by El Forum - 07-21-2008, 07:29 PM
Caching and headers - by El Forum - 07-21-2008, 07:39 PM
Caching and headers - by El Forum - 07-21-2008, 08:49 PM
Caching and headers - by El Forum - 07-21-2008, 08:55 PM
Caching and headers - by El Forum - 07-21-2008, 10:01 PM
Caching and headers - by El Forum - 07-21-2008, 10:11 PM
Caching and headers - by El Forum - 07-21-2008, 10:15 PM
Caching and headers - by El Forum - 07-21-2008, 10:22 PM
Caching and headers - by El Forum - 07-21-2008, 10:28 PM
Caching and headers - by El Forum - 07-21-2008, 10:36 PM
Caching and headers - by El Forum - 07-21-2008, 10:37 PM
Caching and headers - by El Forum - 07-21-2008, 10:40 PM
Caching and headers - by El Forum - 07-21-2008, 11:26 PM
Caching and headers - by El Forum - 07-22-2008, 10:12 AM
Caching and headers - by El Forum - 07-22-2008, 10:26 AM
Caching and headers - by El Forum - 07-22-2008, 12:21 PM
Caching and headers - by El Forum - 07-22-2008, 01:01 PM
Caching and headers - by El Forum - 07-22-2008, 01:09 PM
Caching and headers - by El Forum - 07-22-2008, 01:14 PM
Caching and headers - by El Forum - 07-22-2008, 01:37 PM
Caching and headers - by El Forum - 07-22-2008, 01:44 PM
Caching and headers - by El Forum - 07-22-2008, 03:39 PM
Caching and headers - by El Forum - 07-22-2008, 03:42 PM
Caching and headers - by El Forum - 07-22-2008, 03:43 PM
Caching and headers - by El Forum - 07-22-2008, 03:49 PM
Caching and headers - by El Forum - 07-22-2008, 04:08 PM
Caching and headers - by El Forum - 07-22-2008, 04:31 PM
Caching and headers - by El Forum - 07-22-2008, 04:45 PM
Caching and headers - by El Forum - 07-22-2008, 04:47 PM
Caching and headers - by El Forum - 07-22-2008, 04:59 PM
Caching and headers - by El Forum - 07-22-2008, 05:49 PM
Caching and headers - by El Forum - 07-22-2008, 06:58 PM
Caching and headers - by El Forum - 07-22-2008, 06:59 PM
Caching and headers - by El Forum - 07-22-2008, 07:30 PM
Caching and headers - by El Forum - 07-22-2008, 08:08 PM
Caching and headers - by El Forum - 07-22-2008, 08:58 PM
Caching and headers - by El Forum - 07-22-2008, 08:59 PM
Caching and headers - by El Forum - 10-27-2008, 03:55 AM
Caching and headers - by El Forum - 10-27-2008, 10:33 AM
Caching and headers - by El Forum - 10-27-2008, 11:55 AM
Caching and headers - by El Forum - 11-11-2008, 03:59 AM
Caching and headers - by El Forum - 11-11-2008, 05:29 AM
Caching and headers - by El Forum - 11-11-2008, 06:08 AM
Caching and headers - by El Forum - 11-11-2008, 01:12 PM
Caching and headers - by El Forum - 11-12-2008, 12:11 AM
Caching and headers - by El Forum - 11-12-2008, 03:25 AM
Caching and headers - by El Forum - 11-12-2008, 04:28 AM
Caching and headers - by El Forum - 11-12-2008, 04:45 AM
Caching and headers - by El Forum - 11-12-2008, 06:48 AM
Caching and headers - by El Forum - 11-12-2008, 07:22 AM
Caching and headers - by El Forum - 11-12-2008, 07:55 AM
Caching and headers - by El Forum - 11-12-2008, 10:44 AM
Caching and headers - by El Forum - 11-13-2008, 03:23 AM
Caching and headers - by El Forum - 11-13-2008, 04:48 AM
Caching and headers - by El Forum - 11-13-2008, 05:17 AM
Caching and headers - by El Forum - 11-13-2008, 05:41 AM
Caching and headers - by El Forum - 11-13-2008, 12:17 PM
Caching and headers - by El Forum - 11-13-2008, 12:27 PM
Caching and headers - by El Forum - 11-13-2008, 12:34 PM
Caching and headers - by El Forum - 11-17-2008, 03:12 AM
Caching and headers - by El Forum - 11-17-2008, 05:01 AM
Caching and headers - by El Forum - 11-17-2008, 07:32 AM
Caching and headers - by El Forum - 11-17-2008, 07:57 AM
Caching and headers - by El Forum - 11-17-2008, 03:26 PM
Caching and headers - by El Forum - 11-17-2008, 03:45 PM
Caching and headers - by El Forum - 11-17-2008, 10:53 PM
Caching and headers - by El Forum - 11-18-2008, 02:47 AM
Caching and headers - by El Forum - 11-18-2008, 03:18 AM
Caching and headers - by El Forum - 06-23-2009, 03:40 AM
Caching and headers - by El Forum - 01-22-2010, 08:22 AM
Caching and headers - by El Forum - 06-04-2012, 10:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB