PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / lib / Minify / Cache / ZendPlatform.php

ZendPlatform.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.3, at vendor/mrclay/minify/lib/Minify/Cache/ZendPlatform.php

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