Login   Register  
PHP Classes
elePHPant
Icontem

File: example/trait-disk-example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Oscar Gentilezza  >  Hybrid Cache  >  example/trait-disk-example.php  >  Download  
File: example/trait-disk-example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Hybrid Cache
Store key-value pairs in different containers
Author: By
Last change:
Date: 1 year ago
Size: 789 bytes
 

Contents

Class file image Download
<?php

require('../lib/init.php');

define('CACHE_DATA_FOLDER'dirname(__FILE__)."/cache-folder");

use 
Hybrid\Cache;
use 
Hybrid\storages\Disk as DiskStorage;

class 
ExampleClass {
    
    use 
Hybrid\Cacheable;
    
    public function 
heavyProcess () {
        
        if (
$cacheData $this->isCached(__FILE__,__METHOD__)) {
            return 
$cacheData;
        }
        
        
// heavy proccess:
        
sleep(3);
        
        
$data md5(microtime());
        
        return 
$this->saveCache($data__FILE__,__METHOD__);
        
    }
    
}

echo 
"Generating data (firt time)\n";

$ins = new ExampleClass();

echo 
"data: " $ins->heavyProcess() . "\n";

echo 
"Generating data (second time)\n";

$insb = new ExampleClass();

echo 
"data: " $insb->heavyProcess() . "\n";