<?php include_once 'cache.class.php'; error_reporting(E_ALL ^ E_DEPRECATED); $cache = new EasyCache(array('host' => '127.0.0.1', 'username' => 'root', 'password' => 'root')); $key = 'abc'; if ($content = $cache->get($key)) { echo "Displaying from cache\n"; echo "Key:" . $key . "\n"; echo "Content:" . $content . "\n"; } else { $content = "Key of this cache is " . $key; echo "Key:" . $key . "\n"; echo "Content:" . $content . "\n"; try { $cache->save($key, $content, 20); } catch (Exception $e) { echo $e; } }
/** * create our object. where and how long to store it. * * @param $table - the name of the table in the database to store the cache. */ public function __construct($table = "easy_cache") { parent::__construct(); $this->table = $table; }
/** * create our object. where and how long to store it. * * @param $path string the path to store the object. the hash of the data name * will be appended directly after this. */ public function __construct($path = "/tmp/EasyCache/") { parent::__construct(); $this->path = $path; //make sure our cache directory exists. if (!is_dir($this->path)) { mkdir($this->path, 0777, true); } }