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 if (! $this->_fetch($id)) {
60 return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
61 ? mb_strlen($this->_data, '8bit')
62 : strlen($this->_data);
66 * Does a valid cache entry exist?
68 * @param string $id cache id
70 * @param int $srcMtime mtime of the original source file(s)
74 public function isValid($id, $srcMtime)
76 return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
80 * Send the cached content to output
82 * @param string $id cache id
84 public function display($id)
86 echo $this->_fetch($id)
92 * Fetch the cached content
94 * @param string $id cache id
98 public function fetch($id)
100 return $this->_fetch($id)
105 private $_exp = null;
107 // cache of most recently fetched id
109 private $_data = null;
113 * Fetch data and timestamp from apc, store in instance
117 * @return bool success
119 private function _fetch($id)
121 if ($this->_id === $id) {
124 $ret = apc_fetch($id);
125 if (false === $ret) {
129 list($this->_lm, $this->_data) = explode('|', $ret, 2);