[wp-hackers] Adding a cache to WP
Luc Saint-Elie
luc at saint-elie.com
Mon Jun 28 21:37:45 UTC 2004
Hello,
I seem to end in implementing successfully a cache for WP.
It's based on PEAR :Cache_Lite
I had a lot of problem coming from my own output buffering
implementation..until I realized Cache_Lite provides output buffering
(the conclusion is that PER developers are better than I am.. but I
knew that already and that's not difficult :-) )
I'm not at all a developer so if someone could test (and correct if I
did something wrong).
In my opinion providing a caching system would be a major strong point for WP
The process is :
1- download PEAR :Cache_Lite at :
http://pear.php.net/package/Cache_Lite/download
2- unpack and place the directory in your include directory
3- create a tmp directory if it doesn't exist
4- in index.php do
<?php
// set the include path (depends on each hosting)
ini_set('include_path','.:'
.$_SERVER['DOCUMENT_ROOT'].'/include/:'
.$_SERVER['DOCUMENT_ROOT'].'/include/Cache/:'
.$_SERVER['DOCUMENT_ROOT'].'/include/Cache/Lite');
/* Don't remove this line. */
require('./wp-blog-header.php');
// include the package
require_once "Cache/Lite/Output.php";
// set an ID for this cache
$id = $_SERVER['REQUEST_URI'];
if ( $id =='/') {
$id ='home';
}
// set some variables
$options = array(
'cacheDir' => 'tmp/',
'lifeTime' => 7200,
'pearErrorMode' => CACHE_LITE_ERROR_DIE
);
// create a Cache_Lite_Output object
$objCache = new Cache_Lite_Output($options);
// test if there exists a valid cache
// test for POST is to avoid screwing comments with cached pages
if ( ! ($objCache->start($id) || $_SERVER['REQUEST_METHOD'] =='POST') )
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
the remaining of the file
<?php
$objCache->end();
}
?>
--
Luc Saint-Elie Journaliste
7, rue Androuet
75018 Paris
Mail: luc at saint-elie.com
Tel : 08 70 73 20 28
Mob : 06 12 90 19 65
http://blog.saint-elie.com
More information about the hackers
mailing list