<?php
require_once 'cache.class.php';
require_once 'fileCacheDriver.class.php';
function getPrinters(){
return array('HP 845C', 'Canon E23', 'Lexmark L45');
}
try {
$cache=new Cache();
$cache->addDriver('file', new FileCacheDriver());
$printers=$cache->get('products', 'printers', 500); # get data identified as printers from group products which is not older than 500 seconds
if($printers===false) { #there is no data in cache
$printers=getPrinters();
$cache->set('products', 'printers', $printers); #set data identified as printers in group products
}
var_dump($printers);
}
catch (CacheException $e){
echo 'Error: '.$e->getMessage();
}
?>
|