Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of chema garrido  >  Wrapper Cache  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: Wrapper Cache
Wrapper to access several types of cache storages
Author: By
Last change:
Date: 2010-10-29 08:27
Size: 1,544 bytes
 

Contents

Class file image Download
<?php
error_reporting
(E_ALL); 
ini_set("display_errors"1); 
 

//optional code in neo22s.com/filecache
include 'fileCache.php';
//file wrapper cache example
include 'wrapperCache.php';


//creating new instance singleton
$cache wrapperCache::GetInstance('filecache',36,'cache/');//all params are optional
//or set it in auto and the class will choose the cache engine for you ;)
//$cache = wrapperCache::GetInstance('auto');

//caching values
$cache->thevar='I\'m the bar from wrapper cache using filecache';//overload of set and get methods
//or:
$cache->cache('thevar','test values for the var!!!!');

//retrieving value for a key
echo $cache->thevar;//get
//or:
echo $cache->cache('thevar');//get

//isset and unset are overloaded
var_dump(isset($cache->thevar));
unset(
$cache->thevar);

//displays availables cache engines in your system:
echo $cache->getAvailableCache();

//flush all cache
$cache->clearCache();



//example to add multiple servers of memcache
/*$memcache_servers = 
        array (
                array('host'=>'localhost','port'=>11211),
                array('host'=>'172.16.0.3')
        );

$cache = wrapperCache::GetInstance('memcache',30, $memcache_servers );//creating new instance singleton*/

//or simpler way:
$cache wrapperCache::GetInstance('memcache',30,array(array('host'=>'localhost')));

if (
$cache->site==null){
    echo 
'inside';
    
$cache->cache('site',strip_tags(file_get_contents("http://yahoo.com")),100);//time overload
}
echo 
$cache->site;

//end wrapper cache example

?>