Minify_Cache_ZendPlatform

ZendPlatform-based cache class for Minify.

Defined (1)

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

/lib/Minify/Minify/Cache/ZendPlatform.php  
  1. class Minify_Cache_ZendPlatform { 
  2.  
  3.  
  4. /** 
  5. * Create a Minify_Cache_ZendPlatform object, to be passed to 
  6. * Minify::setCache(). 
  7. * @param int $expire seconds until expiration (default = 0 
  8. * meaning the item will not get an expiration date) 
  9. * @return null 
  10. */ 
  11. public function __construct($expire = 0) 
  12. $this->_exp = $expire; 
  13.  
  14.  
  15. /** 
  16. * Write data to cache. 
  17. * @param string $id cache id 
  18. * @param string $data 
  19. * @return bool success 
  20. */ 
  21. public function store($id, $data) 
  22. return output_cache_put($id, "{$_SERVER['REQUEST_TIME']}|{$data}"); 
  23.  
  24.  
  25. /** 
  26. * Get the size of a cache entry 
  27. * @param string $id cache id 
  28. * @return int size in bytes 
  29. */ 
  30. public function getSize($id) 
  31. return $this->_fetch($id) 
  32. ? strlen($this->_data) 
  33. : false; 
  34.  
  35.  
  36. /** 
  37. * Does a valid cache entry exist? 
  38. * @param string $id cache id 
  39. * @param int $srcMtime mtime of the original source file(s) 
  40. * @return bool exists 
  41. */ 
  42. public function isValid($id, $srcMtime) 
  43. $ret = ($this->_fetch($id) && ($this->_lm >= $srcMtime)); 
  44. return $ret; 
  45.  
  46.  
  47. /** 
  48. * Send the cached content to output 
  49. * @param string $id cache id 
  50. */ 
  51. public function display($id) 
  52. echo $this->_fetch($id) 
  53. ? $this->_data 
  54. : ''; 
  55.  
  56.  
  57. /** 
  58. * Fetch the cached content 
  59. * @param string $id cache id 
  60. * @return string 
  61. */ 
  62. public function fetch($id) 
  63. return $this->_fetch($id) 
  64. ? $this->_data 
  65. : ''; 
  66.  
  67.  
  68. private $_exp = null; 
  69.  
  70.  
  71. // cache of most recently fetched id 
  72. private $_lm = null; 
  73. private $_data = null; 
  74. private $_id = null; 
  75.  
  76.  
  77. /** 
  78. * Fetch data and timestamp from ZendPlatform, store in instance 
  79. * @param string $id 
  80. * @return bool success 
  81. */ 
  82. private function _fetch($id) 
  83. if ($this->_id === $id) { 
  84. return true; 
  85. $ret = output_cache_get($id, $this->_exp); 
  86. if (false === $ret) { 
  87. $this->_id = null; 
  88. return false; 
  89. list($this->_lm, $this->_data) = explode('|', $ret, 2); 
  90. $this->_id = $id; 
  91. return true;