SHARE
TWEET

Untitled

a guest Oct 31st, 2011 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.     class Cache{
  4.     private $folder = 'cache';
  5.     private $timeout = 3600; //1hora
  6.     private $name;
  7.  
  8.           public function __construct($file, $timeout){
  9.                         $this->name = $file;
  10.                    $this->timeout = $timeout;
  11.                         if($this->check()){
  12.                                  $this->createCache();
  13.                         }
  14.            }
  15.  
  16.          public function getPathFileName(){
  17.                  return sprintf('%s/%s', $this->folder, md5($this->name));
  18.         }
  19.           public function check(){
  20.                   $file = $this->getPathFileName();
  21.                   if(file_exists($file) && ( fileatime ( $file ) + $this->timeout) > time()) {
  22.                          return true;
  23.                   }else{
  24.                         return false;
  25.                   }
  26.         }
  27.  
  28.         public function createCache(){
  29.                         ob_start();
  30.                         include_once($this->name);
  31.                         file_put_contents($this->getPathFileName(),  ob_get_clean());
  32.         }
  33.  
  34.         public function getContent(){
  35.                   return file_get_contents($this->getPathFileName());
  36.         }
  37.    
  38. }
  39.  
  40. ?>
  41.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top