C_Pope_Cache_SingleFile

The NextGEN Gallery C Pope Cache SingleFile class.

Defined (1)

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

/pope/lib/class.pope_cache.php  
  1. class C_Pope_Cache_SingleFile implements I_Pope_Cache_Driver 
  2. static $initialized = FALSE; 
  3. static $cache_dir = NULL; 
  4. static $cache = array(); 
  5. static $writepending = FALSE; 
  6.  
  7. public static function initialize() 
  8. if (self::$initialized) 
  9. return; 
  10.  
  11. if (is_null(self::$cache_dir)) 
  12. self::set_cache_dir(); 
  13.  
  14. $filename = self::get_filename(); 
  15. if (@file_exists($filename)) 
  16. self::$cache = json_decode(@file_get_contents($filename), TRUE); 
  17.  
  18. if (!is_array(self::$cache)) 
  19. self::$cache = array(); 
  20.  
  21. register_shutdown_function('C_Pope_Cache_SingleFile_Shutdown'); 
  22.  
  23. self::$initialized = TRUE; 
  24.  
  25. public static function add_key_prefix($prefix) 
  26. self::set_cache_dir(); 
  27.  
  28. public static function lookup($key, $default=NULL) 
  29. self::initialize(); 
  30.  
  31. if (!empty(self::$cache[$key])) 
  32. return self::$cache[$key]; 
  33. else 
  34. return $default; 
  35.  
  36. public static function update($key, $value) 
  37. self::initialize(); 
  38.  
  39. $dupe = FALSE; 
  40.  
  41. if (!empty(self::$cache[$key])) { 
  42. if (self::$cache[$key] == $value) 
  43. $dupe = TRUE; 
  44.  
  45. if ($dupe == TRUE && C_Pope_Cache::$force_update == FALSE) 
  46. return; 
  47.  
  48. self::$cache[$key] = $value; 
  49. self::$writepending = TRUE; 
  50.  
  51. public static function flush() 
  52. self::initialize(); 
  53. $filename = self::get_filename(); 
  54. if (@file_exists($filename)) 
  55. @unlink($filename); 
  56.  
  57. public static function get_filename() 
  58. if (count(C_Pope_Cache::$key_prefix) == 1) 
  59. C_Pope_Cache::add_key_prefix('cache'); 
  60. $filename = implode('_', C_Pope_Cache::$key_prefix); 
  61. return self::join_paths(self::$cache_dir, $filename); 
  62.  
  63. public static function set_cache_dir() 
  64. if (defined('POPE_CACHE_DIR')) 
  65. self::$cache_dir = POPE_CACHE_DIR; 
  66. if (!@file_exists(self::$cache_dir)) 
  67. @mkdir(self::$cache_dir, 0777, TRUE); 
  68. else { 
  69. self::$cache_dir = self::join_paths(sys_get_temp_dir()); 
  70.  
  71. $func = function_exists('wp_is_writable') ? 'wp_is_writable' : 'is_writable'; 
  72. if (!@$func(self::$cache_dir)) 
  73. C_Pope_Cache::$enabled = FALSE; 
  74.  
  75. public static function join_paths() 
  76. $args = func_get_args(); 
  77. foreach ($args as &$arg) { 
  78. if (is_array($arg)) 
  79. $arg = implode(DIRECTORY_SEPARATOR, $arg); 
  80. return implode(DIRECTORY_SEPARATOR, $args);