summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Roberts <eric@cryode.com>2013-01-12 04:20:54 +0100
committerEric Roberts <eric@cryode.com>2013-01-12 04:20:54 +0100
commitc90e67ea553f1ff0fc22f280583fca22f95f9f42 (patch)
treed37073ed3af32e2c841e8fdd5a0ee2e0b1aaf0de
parent78fa58a66f4e0d31043f0d3d8a64088fb8900361 (diff)
Improve output cache.
-rw-r--r--system/core/Output.php34
1 files changed, 24 insertions, 10 deletions
diff --git a/system/core/Output.php b/system/core/Output.php
index 27e711783..52a551858 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -58,21 +58,21 @@ class CI_Output {
*
* @var array
*/
- public $headers = array();
+ public $headers = array();
/**
* List of mime types
*
* @var array
*/
- public $mimes = array();
+ public $mimes = array();
/**
* Mime-type for the current page
*
* @var string
*/
- protected $mime_type = 'text/html';
+ protected $mime_type = 'text/html';
/**
* Enable Profiler flag
@@ -86,14 +86,14 @@ class CI_Output {
*
* @var bool
*/
- protected $_zlib_oc = FALSE;
+ protected $_zlib_oc = FALSE;
/**
* List of profiler sections
*
* @var array
*/
- protected $_profiler_sections = array();
+ protected $_profiler_sections = array();
/**
* Parse markers flag
@@ -102,7 +102,7 @@ class CI_Output {
*
* @var bool
*/
- public $parse_exec_vars = TRUE;
+ public $parse_exec_vars = TRUE;
/**
* Class constructor
@@ -543,10 +543,16 @@ class CI_Output {
}
$expire = time() + ($this->cache_expiration * 60);
+
+ // Put together our serialized info.
+ $cache_info = serialize(array(
+ 'expire' => $expire,
+ 'headers' => $this->headers
+ ));
if (flock($fp, LOCK_EX))
{
- fwrite($fp, $expire.'TS--->'.$output);
+ fwrite($fp, $cache_info.'ENDCI--->'.$output);
flock($fp, LOCK_UN);
}
else
@@ -595,14 +601,16 @@ class CI_Output {
flock($fp, LOCK_UN);
fclose($fp);
- // Strip out the embedded timestamp
- if ( ! preg_match('/^(\d+)TS--->/', $cache, $match))
+ // Look for embedded serialized file info.
+ if ( ! preg_match('/^(.*)ENDCI--->/', $cache, $match))
{
return FALSE;
}
+
+ $cache_info = unserialize($match[1]);
+ $expire = $cache_info['expire'];
$last_modified = filemtime($cache_path);
- $expire = $match[1];
// Has the file expired?
if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path))
@@ -617,6 +625,12 @@ class CI_Output {
// Or else send the HTTP cache control headers.
$this->set_cache_header($last_modified, $expire);
}
+
+ // Add headers from cache file.
+ foreach ($cache_info['headers'] as $header)
+ {
+ $this->set_header($header[0], $header[1]);
+ }
// Display the cache
$this->_display(substr($cache, strlen($match[0])));