3 * Class Minify_Cache_XCache
5 * @link http://xcache.lighttpd.net/
10 * XCache-based cache class for Minify
11 * {@see http://xcache.lighttpd.net/wiki/XcacheApi XCache API}
14 * Minify::setCache(new Minify_Cache_XCache());
18 * @author Elan Ruusamäe <glen@delfi.ee>
20 class Minify_Cache_XCache {
23 * Create a Minify_Cache_XCache object, to be passed to
26 * @param int $expire seconds until expiration (default = 0
27 * 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
39 * @return bool success
41 public function store($id, $data)
43 return xcache_set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
47 * Get the size of a cache entry
49 * @param string $id cache id
50 * @return int size in bytes
52 public function getSize($id)
54 if (! $this->_fetch($id)) {
57 return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
58 ? mb_strlen($this->_data, '8bit')
59 : strlen($this->_data);
63 * Does a valid cache entry exist?
65 * @param string $id cache id
66 * @param int $srcMtime mtime of the original source file(s)
69 public function isValid($id, $srcMtime)
71 return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
75 * Send the cached content to output
77 * @param string $id cache id
79 public function display($id)
81 echo $this->_fetch($id)
87 * Fetch the cached content
89 * @param string $id cache id
92 public function fetch($id)
94 return $this->_fetch($id)
101 // cache of most recently fetched id
103 private $_data = null;
107 * Fetch data and timestamp from xcache, store in instance
110 * @return bool success
112 private function _fetch($id)
114 if ($this->_id === $id) {
117 $ret = xcache_get($id);
118 if (false === $ret) {
122 list($this->_lm, $this->_data) = explode('|', $ret, 2);