PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of MatheW   Cache library   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example use of library
Class: Cache library
Cache arbitrary data in files
Author: By
Last change:
Date: 16 years ago
Size: 694 bytes
 

Contents

Class file image Download
<?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();
    }
?>