[eluser]Patrick Savalle[/eluser]
Most serious installations have APC enabled. When using APC you can use it for output caching also. Just place this class in application/core/MY_Ouput.php and your output caching will use APC, avoiding disk-writes and reads.
As a bonus this version also saves the HTTP header with the cache.
Code:
<?php
if ( !defined( 'BASEPATH' ) )
exit( 'No direct script access allowed' );
/**
* APC Output caching class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Core
* @author Patrick Savalle
* @link
*
* Overrides the caching method of the standard CI_Output class
*
* Generates an error when APC is not installed.
*/
class MY_Output extends CI_Output
{
static private function construct_key( )
{
return $_SERVER["REQUEST_URI"];
}
function _write_cache( $output )
{
apc_store( self::construct_key( ), array( $this->headers, $output ), (int)($this->cache_expiration * 60) );
}
function _display_cache( &$CFG, &$URI )
{
$cache = apc_fetch( self::construct_key( ), $success );
if ( $success )
{
list( $headers, $output ) = $cache;
if ( count( $headers ) > 0 )
{
foreach ( $headers as $header )
{
header( $header[0], $header[1] );
}
}
echo $output;
return TRUE;
}
return FALSE;
}
}