PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 1.7.3
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v1.7.3
4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / freemius / includes / managers / class-fs-cache-manager.php
embedpress / freemius / includes / managers Last commit date
class-fs-admin-menu-manager.php 9 years ago class-fs-admin-notice-manager.php 9 years ago class-fs-cache-manager.php 9 years ago class-fs-key-value-storage.php 9 years ago class-fs-license-manager.php 9 years ago class-fs-option-manager.php 9 years ago class-fs-plan-manager.php 9 years ago class-fs-plugin-manager.php 9 years ago index.php 9 years ago
class-fs-cache-manager.php
237 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
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 );
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 *
120 * @return bool
121 */
122 function has_valid( $key ) {
123 $cache_entry = $this->_options->get_option( $key, false );
124
125 return ( is_object( $cache_entry ) &&
126 isset( $cache_entry->timestamp ) &&
127 is_numeric( $cache_entry->timestamp ) &&
128 $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
129 );
130 }
131
132 /**
133 * @author Vova Feldman (@svovaf)
134 * @since 1.1.6
135 *
136 * @param string $key
137 * @param mixed $default
138 *
139 * @return mixed
140 */
141 function get( $key, $default = null ) {
142 $this->_logger->entrance( 'key = ' . $key );
143
144 $cache_entry = $this->_options->get_option( $key, false );
145
146 if ( is_object( $cache_entry ) &&
147 isset( $cache_entry->timestamp ) &&
148 is_numeric( $cache_entry->timestamp )
149 ) {
150 return $cache_entry->result;
151 }
152
153 return $default;
154 }
155
156 /**
157 * @author Vova Feldman (@svovaf)
158 * @since 1.1.6
159 *
160 * @param string $key
161 * @param mixed $default
162 *
163 * @return mixed
164 */
165 function get_valid( $key, $default = null ) {
166 $this->_logger->entrance( 'key = ' . $key );
167
168 $cache_entry = $this->_options->get_option( $key, false );
169
170 if ( is_object( $cache_entry ) &&
171 isset( $cache_entry->timestamp ) &&
172 is_numeric( $cache_entry->timestamp ) &&
173 $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
174 ) {
175 return $cache_entry->result;
176 }
177
178 return $default;
179 }
180
181 /**
182 * @author Vova Feldman (@svovaf)
183 * @since 1.1.6
184 *
185 * @param string $key
186 * @param mixed $value
187 * @param int $expiration
188 */
189 function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
190 $this->_logger->entrance( 'key = ' . $key );
191
192 $cache_entry = new stdClass();
193 $cache_entry->result = $value;
194 $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
195 $this->_options->set_option( $key, $cache_entry, true );
196 }
197
198 /**
199 * Get cached record expiration, or false if not cached or expired.
200 *
201 * @author Vova Feldman (@svovaf)
202 * @since 1.1.7.3
203 *
204 * @param string $key
205 *
206 * @return bool|int
207 */
208 function get_record_expiration( $key ) {
209 $this->_logger->entrance( 'key = ' . $key );
210
211 $cache_entry = $this->_options->get_option( $key, false );
212
213 if ( is_object( $cache_entry ) &&
214 isset( $cache_entry->timestamp ) &&
215 is_numeric( $cache_entry->timestamp ) &&
216 $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
217 ) {
218 return $cache_entry->timestamp;
219 }
220
221 return false;
222 }
223
224 /**
225 * Purge cached item.
226 *
227 * @author Vova Feldman (@svovaf)
228 * @since 1.1.6
229 *
230 * @param string $key
231 */
232 function purge( $key ) {
233 $this->_logger->entrance( 'key = ' . $key );
234
235 $this->_options->unset_option( $key, true );
236 }
237 }