3 * Class Minify_Cache_APC
8 * APC-based cache class for Minify
11 * Minify::setCache(new Minify_Cache_APC());
15 * @author Chris Edwards
17 class Minify_Cache_APC {
20 * Create a Minify_Cache_APC object, to be passed to
24 * @param int $expire seconds until expiration (default = 0
25 * meaning the item will not get an expiration date)
29 public function __construct($expire = 0)
31 $this->_exp = $expire;
35 * Write data to cache.
37 * @param string $id cache id
41 * @return bool success
43 public function store($id, $data)
45 return apc_store($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
49 * Get the size of a cache entry
51 * @param string $id cache id
53 * @return int size in bytes
55 public function getSize($id)
57 return $this->_fetch($id)
58 ? strlen($this->_data)
63 * Does a valid cache entry exist?
65 * @param string $id cache id
67 * @param int $srcMtime mtime of the original source file(s)
71 public function isValid($id, $srcMtime)
73 return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
77 * Send the cached content to output
79 * @param string $id cache id
81 public function display($id)
83 echo $this->_fetch($id)
89 * Fetch the cached content
91 * @param string $id cache id
95 public function fetch($id)
97 return $this->_fetch($id)
102 private $_exp = null;
104 // cache of most recently fetched id
106 private $_data = null;
110 * Fetch data and timestamp from apc, store in instance
114 * @return bool success
116 private function _fetch($id)
118 if ($this->_id === $id) {
121 $ret = apc_fetch($id);
122 if (false === $ret) {
126 list($this->_lm, $this->_data) = explode('|', $ret, 2);