JG_Cache

For explanation and usage, see:.

Defined (2)

The class is defined in the following location(s).

/admin/class-cws-google-picasa-pro-admin.php  
  1. class JG_Cache { 
  2.  
  3. function __construct($dir) 
  4. $this->dir = $dir; 
  5. // error_log("JG CACHE: dir: $dir"); 
  6.  
  7. private function _name($key) 
  8. return sprintf("%s/%s", $this->dir, sha1($key)); 
  9.  
  10. public function get($key, $expiration = 3600) 
  11.  
  12. if ( !is_dir($this->dir) OR !is_writable($this->dir)) 
  13. return FALSE; 
  14.  
  15. $cache_path = $this->_name($key); 
  16.  
  17. if (!@file_exists($cache_path)) 
  18. return FALSE; 
  19.  
  20. if (filemtime($cache_path) < (time() - $expiration)) 
  21. $this->clear($key); 
  22. return FALSE; 
  23.  
  24. if (!$fp = @fopen($cache_path, 'rb')) 
  25. return FALSE; 
  26.  
  27. flock($fp, LOCK_SH); 
  28.  
  29. $cache = ''; 
  30.  
  31. if (filesize($cache_path) > 0) 
  32. $cache = unserialize(fread($fp, filesize($cache_path))); 
  33. else 
  34. $cache = NULL; 
  35.  
  36. flock($fp, LOCK_UN); 
  37. fclose($fp); 
  38.  
  39. return $cache; 
  40.  
  41. public function set($key, $data) 
  42.  
  43. if ( !is_dir($this->dir) OR !is_writable($this->dir)) 
  44. return FALSE; 
  45.  
  46. $cache_path = $this->_name($key); 
  47.  
  48. if ( ! $fp = fopen($cache_path, 'wb')) 
  49. return FALSE; 
  50.  
  51. if (flock($fp, LOCK_EX)) 
  52. fwrite($fp, serialize($data)); 
  53. flock($fp, LOCK_UN); 
  54. else 
  55. return FALSE; 
  56. fclose($fp); 
  57. @chmod($cache_path, 0777); 
  58. return TRUE; 
  59.  
  60. public function clear($key) 
  61. $cache_path = $this->_name($key); 
  62.  
  63. if (file_exists($cache_path)) 
  64. unlink($cache_path); 
  65. return TRUE; 
  66.  
  67. return FALSE; 
  1. class JG_Cache { 
  2.  
  3. function __construct($dir) 
  4. $this->dir = $dir; 
  5. // error_log("JG CACHE: dir: $dir"); 
  6.  
  7. private function _name($key) 
  8. return sprintf("%s/%s", $this->dir, sha1($key)); 
  9.  
  10. public function get($key, $expiration = 3600) 
  11.  
  12. if ( !is_dir($this->dir) OR !is_writable($this->dir)) 
  13. return FALSE; 
  14.  
  15. $cache_path = $this->_name($key); 
  16.  
  17. if (!@file_exists($cache_path)) 
  18. return FALSE; 
  19.  
  20. if (filemtime($cache_path) < (time() - $expiration)) 
  21. $this->clear($key); 
  22. return FALSE; 
  23.  
  24. if (!$fp = @fopen($cache_path, 'rb')) 
  25. return FALSE; 
  26.  
  27. flock($fp, LOCK_SH); 
  28.  
  29. $cache = ''; 
  30.  
  31. if (filesize($cache_path) > 0) 
  32. $cache = unserialize(fread($fp, filesize($cache_path))); 
  33. else 
  34. $cache = NULL; 
  35.  
  36. flock($fp, LOCK_UN); 
  37. fclose($fp); 
  38.  
  39. return $cache; 
  40.  
  41. public function set($key, $data) 
  42.  
  43. if ( !is_dir($this->dir) OR !is_writable($this->dir)) 
  44. return FALSE; 
  45.  
  46. $cache_path = $this->_name($key); 
  47.  
  48. if ( ! $fp = fopen($cache_path, 'wb')) 
  49. return FALSE; 
  50.  
  51. if (flock($fp, LOCK_EX)) 
  52. fwrite($fp, serialize($data)); 
  53. flock($fp, LOCK_UN); 
  54. else 
  55. return FALSE; 
  56. fclose($fp); 
  57. @chmod($cache_path, 0777); 
  58. return TRUE; 
  59.  
  60. public function clear($key) 
  61. $cache_path = $this->_name($key); 
  62.  
  63. if (file_exists($cache_path)) 
  64. unlink($cache_path); 
  65. return TRUE; 
  66.  
  67. return FALSE;