예제 #1
0
    public $member2 = 'abc';
    function changeDate($var)
    {
        echo "No cache! Heavy read here!...";
        sleep(2);
        echo "done!\n";
        // Lets say this is some heavy compyting here, and the results are written to member1 and 2
        $this->member1[] = $var;
        $this->member2 .= $var;
    }
}
// At a later stage, or another script
$obj = new obj_to_cache();
if (!Cacheable::sCacheRestore($obj, 'changed-str1')) {
    $obj->changeDate('str1');
    Cacheable::sCacheStore($obj, 'changed-str1', CacheExpire::create()->timeout(60));
} else {
    // Cache was hit!
    echo "Cache hit!\n";
}
var_dump($obj);
/**
* Outputs (1st execute):
* 
No cache! Heavy read here!...done!
object(obj_to_cache)#1 (2) {
 ["member1"]=>
 array(2) {
   ["a"]=>
   int(1)
   [0]=>