PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / freemius / includes / managers / class-fs-cache-manager.php
royal-elementor-addons / freemius / includes / managers Last commit date
class-fs-admin-menu-manager.php 5 days ago class-fs-admin-notice-manager.php 5 days ago class-fs-cache-manager.php 5 days ago class-fs-checkout-manager.php 5 days ago class-fs-clone-manager.php 5 days ago class-fs-contact-form-manager.php 5 days ago class-fs-debug-manager.php 5 days ago class-fs-gdpr-manager.php 5 days ago class-fs-key-value-storage.php 5 days ago class-fs-license-manager.php 5 days ago class-fs-option-manager.php 5 days ago class-fs-permission-manager.php 5 days ago class-fs-plan-manager.php 5 days ago class-fs-plugin-manager.php 5 days ago index.php 5 days ago
class-fs-cache-manager.php
326 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 1.1.6
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class FS_Cache_Manager {
14 /**
15 * @var FS_Option_Manager
16 */
17 private $_options;
18 /**
19 * @var FS_Logger
20 */
21 private $_logger;
22
23 /**
24 * @var FS_Cache_Manager[]
25 */
26 private static $_MANAGERS = array();
27
28 /**
29 * @author Vova Feldman (@svovaf)
30 * @since 1.1.3
31 *
32 * @param string $id
33 */
34 private function __construct( $id ) {
35 $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
37 $this->_logger->entrance();
38 $this->_logger->log( 'id = ' . $id );
39
40 $this->_options = FS_Option_Manager::get_manager( $id, true, true, false );
41 }
42
43 /**
44 * @author Vova Feldman (@svovaf)
45 * @since 1.1.6
46 *
47 * @param $id
48 *
49 * @return FS_Cache_Manager
50 */
51 static function get_manager( $id ) {
52 $id = strtolower( $id );
53
54 if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55 self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56 }
57
58 return self::$_MANAGERS[ $id ];
59 }
60
61 /**
62 * @author Vova Feldman (@svovaf)
63 * @since 1.1.6
64 *
65 * @return bool
66 */
67 function is_empty() {
68 $this->_logger->entrance();
69
70 return $this->_options->is_empty();
71 }
72
73 /**
74 * @author Vova Feldman (@svovaf)
75 * @since 1.1.6
76 */
77 function clear() {
78 $this->_logger->entrance();
79
80 $this->_options->clear( true );
81 }
82
83 /**
84 * Delete cache manager from DB.
85 *
86 * @author Vova Feldman (@svovaf)
87 * @since 1.0.9
88 */
89 function delete() {
90 $this->_options->delete();
91 }
92
93 /**
94 * Check if there's a cached item.
95 *
96 * @author Vova Feldman (@svovaf)
97 * @since 1.1.6
98 *
99 * @param string $key
100 *
101 * @return bool
102 */
103 function has( $key ) {
104 $cache_entry = $this->_options->get_option( $key, false );
105
106 return ( is_object( $cache_entry ) &&
107 isset( $cache_entry->timestamp ) &&
108 is_numeric( $cache_entry->timestamp )
109 );
110 }
111
112 /**
113 * Check if there's a valid cached item.
114 *
115 * @author Vova Feldman (@svovaf)
116 * @since 1.1.6
117 *
118 * @param string $key
119 * @param null|int $expiration Since 1.2.2.7
120 *
121 * @return bool
122 */
123 function has_valid( $key, $expiration = null ) {
124 $cache_entry = $this->_options->get_option( $key, false );
125
126 $is_valid = ( is_object( $cache_entry ) &&
127 isset( $cache_entry->timestamp ) &&
128 is_numeric( $cache_entry->timestamp ) &&
129 $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
130 );
131
132 if ( $is_valid &&
133 is_numeric( $expiration ) &&
134 isset( $cache_entry->created ) &&
135 is_numeric( $cache_entry->created ) &&
136 $cache_entry->created + $expiration < WP_FS__SCRIPT_START_TIME
137 ) {
138 /**
139 * Even if the cache is still valid, since we are checking for validity
140 * with an explicit expiration period, if the period has past, return
141 * `false` as if the cache is invalid.
142 *
143 * @since 1.2.2.7
144 */
145 $is_valid = false;
146 }
147
148 return $is_valid;
149 }
150
151 /**
152 * @author Vova Feldman (@svovaf)
153 * @since 1.1.6
154 *
155 * @param string $key
156 * @param mixed $default
157 *
158 * @return mixed
159 */
160 function get( $key, $default = null ) {
161 $this->_logger->entrance( 'key = ' . $key );
162
163 $cache_entry = $this->_options->get_option( $key, false );
164
165 if ( is_object( $cache_entry ) &&
166 isset( $cache_entry->timestamp ) &&
167 is_numeric( $cache_entry->timestamp )
168 ) {
169 return $cache_entry->result;
170 }
171
172 return is_object( $default ) ? clone $default : $default;
173 }
174
175 /**
176 * @author Vova Feldman (@svovaf)
177 * @since 1.1.6
178 *
179 * @param string $key
180 * @param mixed $default
181 *
182 * @return mixed
183 */
184 function get_valid( $key, $default = null ) {
185 $this->_logger->entrance( 'key = ' . $key );
186
187 $cache_entry = $this->_options->get_option( $key, false );
188
189 if ( is_object( $cache_entry ) &&
190 isset( $cache_entry->timestamp ) &&
191 is_numeric( $cache_entry->timestamp ) &&
192 $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
193 ) {
194 return $cache_entry->result;
195 }
196
197 return is_object( $default ) ? clone $default : $default;
198 }
199
200 /**
201 * @author Vova Feldman (@svovaf)
202 * @since 1.1.6
203 *
204 * @param string $key
205 * @param mixed $value
206 * @param int $expiration
207 * @param int $created Since 2.0.0 Cache creation date.
208 */
209 function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $created = WP_FS__SCRIPT_START_TIME ) {
210 $this->_logger->entrance( 'key = ' . $key );
211
212 $cache_entry = new stdClass();
213
214 $cache_entry->result = $value;
215 $cache_entry->created = $created;
216 $cache_entry->timestamp = $created + $expiration;
217 $this->_options->set_option( $key, $cache_entry, true );
218 }
219
220 /**
221 * Get cached record expiration, or false if not cached or expired.
222 *
223 * @author Vova Feldman (@svovaf)
224 * @since 1.1.7.3
225 *
226 * @param string $key
227 *
228 * @return bool|int
229 */
230 function get_record_expiration( $key ) {
231 $this->_logger->entrance( 'key = ' . $key );
232
233 $cache_entry = $this->_options->get_option( $key, false );
234
235 if ( is_object( $cache_entry ) &&
236 isset( $cache_entry->timestamp ) &&
237 is_numeric( $cache_entry->timestamp ) &&
238 $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
239 ) {
240 return $cache_entry->timestamp;
241 }
242
243 return false;
244 }
245
246 /**
247 * Purge cached item.
248 *
249 * @author Vova Feldman (@svovaf)
250 * @since 1.1.6
251 *
252 * @param string $key
253 */
254 function purge( $key ) {
255 $this->_logger->entrance( 'key = ' . $key );
256
257 $this->_options->unset_option( $key, true );
258 }
259
260 /**
261 * Extend cached item caching period.
262 *
263 * @author Vova Feldman (@svovaf)
264 * @since 2.0.0
265 *
266 * @param string $key
267 * @param int $expiration
268 *
269 * @return bool
270 */
271 function update_expiration( $key, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
272 $this->_logger->entrance( 'key = ' . $key );
273
274 $cache_entry = $this->_options->get_option( $key, false );
275
276 if ( ! is_object( $cache_entry ) ||
277 ! isset( $cache_entry->timestamp ) ||
278 ! is_numeric( $cache_entry->timestamp )
279 ) {
280 return false;
281 }
282
283 $this->set( $key, $cache_entry->result, $expiration, $cache_entry->created );
284
285 return true;
286 }
287
288 /**
289 * Set cached item as expired.
290 *
291 * @author Vova Feldman (@svovaf)
292 * @since 1.2.2.7
293 *
294 * @param string $key
295 */
296 function expire( $key ) {
297 $this->_logger->entrance( 'key = ' . $key );
298
299 $cache_entry = $this->_options->get_option( $key, false );
300
301 if ( is_object( $cache_entry ) &&
302 isset( $cache_entry->timestamp ) &&
303 is_numeric( $cache_entry->timestamp )
304 ) {
305 // Set to expired.
306 $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME;
307 $this->_options->set_option( $key, $cache_entry, true );
308 }
309 }
310
311 #--------------------------------------------------------------------------------
312 #region Migration
313 #--------------------------------------------------------------------------------
314
315 /**
316 * Migrate options from site level.
317 *
318 * @author Vova Feldman (@svovaf)
319 * @since 2.0.0
320 */
321 function migrate_to_network() {
322 $this->_options->migrate_to_network();
323 }
324
325 #endregion
326 }