caching string data with Cache_Lite

Source code


<?php include('./.config.php');

require(
'Cache/Lite.php');
$id 'yahoo.oddlyenough';

$options = array(
    
'cacheDir' => './cache/',
    
'lifeTime' => 3600    // 1 hour
);
10 
11 
$cache = new Cache_Lite($options);
12 
13 
// for demo purposes, purge the cache if we are accessed 
14 // with ?remove
15 
if (strcasecmp($_SERVER['QUERY_STRING'],'remove')==0) {
16     
$cache->remove($id)    ;
17     exit(
"cache purged");
18 }
19 if (
$data $cache->get($id)) {
20     echo 
"using cached data...<br />";
21     echo 
$data;
22 } else {
23     echo 
"no cache, fetching from network...<br />";
24     include(
'./.fetch_xml_with_socket.php5');
25     
$data fetchRss("rss.news.yahoo.com","/rss/oddlyenough");
26     echo 
'<pre>'htmlspecialchars($data), '</pre>';    
27     if (!
$cache->save($data)) {
28         die( 
"damn! could not write to cache" );    }
29 }
30 include(
'./.footer.php')?>

Output


Warning: require(Cache/Lite.php) [function.require]: failed to open stream: No such file or directory in /home/davidmintz/www/davidmintz.org/php_course/examples/10/file_cache_lite.php5 on line 3

Fatal error: require() [function.require]: Failed opening required 'Cache/Lite.php' (include_path='/usr/home/dmintz/inc/pear:.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/davidmintz/www/davidmintz.org/php_course/examples/10/file_cache_lite.php5 on line 3