3 * Class Minify_Cache_ZendPlatform
9 * ZendPlatform-based cache class for Minify
11 * Based on Minify_Cache_APC, uses output_cache_get/put (currently deprecated)
14 * Minify::setCache(new Minify_Cache_ZendPlatform());
18 * @author Patrick van Dissel
20 class Minify_Cache_ZendPlatform {
24 * Create a Minify_Cache_ZendPlatform object, to be passed to
27 * @param int $expire seconds until expiration (default = 0
28 * meaning the item will not get an expiration date)
32 public function __construct($expire = 0)
34 $this->_exp = $expire;
39 * Write data to cache.
41 * @param string $id cache id
45 * @return bool success
47 public function store($id, $data)
49 return output_cache_put($id, "{$_SERVER['REQUEST_TIME']}|{$data}");
54 * Get the size of a cache entry
56 * @param string $id cache id
58 * @return int size in bytes
60 public function getSize($id)
62 return $this->_fetch($id)
63 ? strlen($this->_data)
69 * Does a valid cache entry exist?
71 * @param string $id cache id
73 * @param int $srcMtime mtime of the original source file(s)
77 public function isValid($id, $srcMtime)
79 $ret = ($this->_fetch($id) && ($this->_lm >= $srcMtime));
85 * Send the cached content to output
87 * @param string $id cache id
89 public function display($id)
91 echo $this->_fetch($id)
98 * Fetch the cached content
100 * @param string $id cache id
104 public function fetch($id)
106 return $this->_fetch($id)
112 private $_exp = null;
115 // cache of most recently fetched id
117 private $_data = null;
122 * Fetch data and timestamp from ZendPlatform, store in instance
126 * @return bool success
128 private function _fetch($id)
130 if ($this->_id === $id) {
133 $ret = output_cache_get($id, $this->_exp);
134 if (false === $ret) {
138 list($this->_lm, $this->_data) = explode('|', $ret, 2);