Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 8th, 2010 | Syntax: PHP | Size: 0.97 KB | Hits: 43 | Expires: Never
Copy text to clipboard
  1. <?php
  2.  
  3. class ControlPanel_Cache extends ControlPanel_Main
  4. {
  5.         public $cacheDir = 'UCP_cache/';
  6.  
  7.         public function _cacheExists($id)
  8.         {
  9.                 if(file_exists($this->cacheDir.$id.'.cache')) {
  10.                         return true;
  11.                 }
  12.                 return false;
  13.         }
  14.  
  15.         public function _saveCache($id,$data)
  16.         {
  17.                 if($this->_cacheExists($id)) {
  18.                         return false;
  19.                 } else {
  20.                         $fp = fopen($this->cacheDir.$id.'.cache','w');
  21.                         fwrite($fp,$data);
  22.                         fclose($fp);
  23.                         return true;
  24.                 }
  25.         }
  26.                        
  27.         public function _getCacheAge($id)
  28.         {
  29.                 if($this->_cacheExists($id)) {
  30.                         $x = time()-filemtime($this->cacheDir.$id.'.cache');
  31.                         //if($x < 0) $x = 0;
  32.                         return (int)$x;
  33.                 }
  34.                 return 0;
  35.         }
  36.  
  37.         public function _deleteCache($id)
  38.         {
  39.                 if($this->_cacheExists($id)) {
  40.                         unlink($this->cacheDir.$id.'.cache');
  41.                         return true;
  42.                 }
  43.                 return false;
  44.         }
  45.  
  46.         public function _loadCache($id)
  47.         {
  48.                 if($this->_cacheExists($id)) {
  49.                         $fp = file_get_contents($this->cacheDir.$id.'.cache');
  50.                         return $fp;
  51.                 }
  52.         }
  53. }
  54. ?>