PluginProbe
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript / trunk
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript vtrunk
trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.4 1.5 1.5.1 1.6 2.0 2.0.1
wp-super-minify / includes / min / lib / Minify / Cache / APC.php

APC.php in WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript trunk, at includes/min/lib/Minify/Cache/APC.php

139 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Minify_Cache_APC
4 * @package Minify
5 */
6
7 /**
8 * APC-based cache class for Minify
9 *
10 * <code>
11 * Minify::setCache(new Minify_Cache_APC());
12 * </code>
13 *
14 * @package Minify
15 * @author Chris Edwards
16 *
17 * @deprecated Use Minify_Cache_APCu
18 **/
19 class Minify_Cache_APC implements Minify_CacheInterface
20 {
21
22 /**
23 * Create a Minify_Cache_APC object, to be passed to
24 * Minify::setCache().
25 *
26 *
27 * @param int $expire seconds until expiration (default = 0
28 * meaning the item will not get an expiration date)
29 *
30 * @return null
31 */
32 public function __construct($expire = 0)
33 {
34 $this->_exp = $expire;
35 }
36
37 /**
38 * Write data to cache.
39 *
40 * @param string $id cache id
41 *
42 * @param string $data
43 *
44 * @return bool success
45 */
46 public function store($id, $data)
47 {
48 return apc_store($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
49 }
50
51 /**
52 * Get the size of a cache entry
53 *
54 * @param string $id cache id
55 *
56 * @return int size in bytes
57 */
58 public function getSize($id)
59 {
60 if (! $this->_fetch($id)) {
61 return false;
62 }
63
64 if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
65 return mb_strlen($this->_data, '8bit');
66 } else {
67 return strlen($this->_data);
68 }
69 }
70
71 /**
72 * Does a valid cache entry exist?
73 *
74 * @param string $id cache id
75 *
76 * @param int $srcMtime mtime of the original source file(s)
77 *
78 * @return bool exists
79 */
80 public function isValid($id, $srcMtime)
81 {
82 return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
83 }
84
85 /**
86 * Send the cached content to output
87 *
88 * @param string $id cache id
89 */
90 public function display($id)
91 {
92 echo $this->_fetch($id) ? $this->_data : '';
93 }
94
95 /**
96 * Fetch the cached content
97 *
98 * @param string $id cache id
99 *
100 * @return string
101 */
102 public function fetch($id)
103 {
104 return $this->_fetch($id) ? $this->_data : '';
105 }
106
107 private $_exp = null;
108
109 // cache of most recently fetched id
110 private $_lm = null;
111 private $_data = null;
112 private $_id = null;
113
114 /**
115 * Fetch data and timestamp from apc, store in instance
116 *
117 * @param string $id
118 *
119 * @return bool success
120 */
121 private function _fetch($id)
122 {
123 if ($this->_id === $id) {
124 return true;
125 }
126 $ret = apc_fetch($id);
127 if (false === $ret) {
128 $this->_id = null;
129
130 return false;
131 }
132
133 list($this->_lm, $this->_data) = explode('|', $ret, 2);
134 $this->_id = $id;
135
136 return true;
137 }
138 }
139