PluginProbe
Advanced Custom Fields (ACF®) / 5.7.9
Advanced Custom Fields (ACF®) v5.7.9
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / includes / cache.php
cache.php
445 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if( ! class_exists('acf_cache') ) :
6
7 class acf_cache {
8
9 // vars
10 var $reference = array(),
11 $active = true;
12
13
14 /*
15 * __construct
16 *
17 * This function will setup the class functionality
18 *
19 * @type function
20 * @date 5/03/2014
21 * @since 5.4.0
22 *
23 * @param n/a
24 * @return n/a
25 */
26
27 function __construct() {
28
29 // prevent ACF from persistent cache
30 wp_cache_add_non_persistent_groups('acf');
31
32 }
33
34
35 /*
36 * is_active
37 *
38 * This function will return true if caching is enabled
39 *
40 * @type function
41 * @date 26/6/17
42 * @since 5.6.0
43 *
44 * @param n/a
45 * @return (bool)
46 */
47
48 function is_active() {
49
50 return $this->active;
51
52 }
53
54
55 /*
56 * enable
57 *
58 * This function will enable ACF caching
59 *
60 * @type function
61 * @date 26/6/17
62 * @since 5.6.0
63 *
64 * @param n/a
65 * @return n/a
66 */
67
68 function enable() {
69
70 $this->active = true;
71
72 }
73
74
75 /*
76 * disable
77 *
78 * This function will disable ACF caching
79 *
80 * @type function
81 * @date 26/6/17
82 * @since 5.6.0
83 *
84 * @param n/a
85 * @return n/a
86 */
87
88 function disable() {
89
90 $this->active = false;
91
92 }
93
94
95 /*
96 * get_key
97 *
98 * This function will check for references and modify the key
99 *
100 * @type function
101 * @date 30/06/2016
102 * @since 5.4.0
103 *
104 * @param $key (string)
105 * @return $key
106 */
107
108 function get_key( $key = '' ) {
109
110 // check for reference
111 if( isset($this->reference[ $key ]) ) {
112
113 $key = $this->reference[ $key ];
114
115 }
116
117
118 // return
119 return $key;
120
121 }
122
123
124
125 /*
126 * isset_cache
127 *
128 * This function will return true if a cached data exists for the given key
129 *
130 * @type function
131 * @date 30/06/2016
132 * @since 5.4.0
133 *
134 * @param $key (string)
135 * @return (boolean)
136 */
137
138 function isset_cache( $key = '' ) {
139
140 // bail early if not active
141 if( !$this->is_active() ) return false;
142
143
144 // vars
145 $key = $this->get_key($key);
146 $found = false;
147
148
149 // get cache
150 $cache = wp_cache_get($key, 'acf', false, $found);
151
152
153 // return
154 return $found;
155
156 }
157
158
159 /*
160 * get_cache
161 *
162 * This function will return cached data for a given key
163 *
164 * @type function
165 * @date 30/06/2016
166 * @since 5.4.0
167 *
168 * @param $key (string)
169 * @return (mixed)
170 */
171
172 function get_cache( $key = '' ) {
173
174 // bail early if not active
175 if( !$this->is_active() ) return false;
176
177
178 // vars
179 $key = $this->get_key($key);
180 $found = false;
181
182
183 // get cache
184 $cache = wp_cache_get($key, 'acf', false, $found);
185
186
187 // return
188 return $cache;
189
190 }
191
192
193 /*
194 * set_cache
195 *
196 * This function will set cached data for a given key
197 *
198 * @type function
199 * @date 30/06/2016
200 * @since 5.4.0
201 *
202 * @param $key (string)
203 * @param $data (mixed)
204 * @return n/a
205 */
206
207 function set_cache( $key = '', $data = '' ) {
208
209 // bail early if not active
210 if( !$this->is_active() ) return false;
211
212
213 // set
214 wp_cache_set($key, $data, 'acf');
215
216
217 // return
218 return $key;
219
220 }
221
222
223 /*
224 * set_cache_reference
225 *
226 * This function will set a reference to cached data for a given key
227 *
228 * @type function
229 * @date 30/06/2016
230 * @since 5.4.0
231 *
232 * @param $key (string)
233 * @param $reference (string)
234 * @return n/a
235 */
236
237 function set_cache_reference( $key = '', $reference = '' ) {
238
239 // bail early if not active
240 if( !$this->is_active() ) return false;
241
242
243 // add
244 $this->reference[ $key ] = $reference;
245
246
247 // resturn
248 return $key;
249
250 }
251
252
253 /*
254 * delete_cache
255 *
256 * This function will delete cached data for a given key
257 *
258 * @type function
259 * @date 30/06/2016
260 * @since 5.4.0
261 *
262 * @param $key (string)
263 * @return n/a
264 */
265
266 function delete_cache( $key = '' ) {
267
268 // bail early if not active
269 if( !$this->is_active() ) return false;
270
271
272 // delete
273 return wp_cache_delete( $key, 'acf' );
274
275 }
276
277 }
278
279
280 // initialize
281 acf()->cache = new acf_cache();
282
283 endif; // class_exists check
284
285
286 /*
287 * acf_is_cache_active
288 *
289 * alias of acf()->cache->is_active()
290 *
291 * @type function
292 * @date 26/6/17
293 * @since 5.6.0
294 *
295 * @param n/a
296 * @return n/a
297 */
298
299 function acf_is_cache_active() {
300
301 return acf()->cache->is_active();
302
303 }
304
305
306 /*
307 * acf_disable_cache
308 *
309 * alias of acf()->cache->disable()
310 *
311 * @type function
312 * @date 26/6/17
313 * @since 5.6.0
314 *
315 * @param n/a
316 * @return n/a
317 */
318
319 function acf_disable_cache() {
320
321 return acf()->cache->disable();
322
323 }
324
325
326 /*
327 * acf_enable_cache
328 *
329 * alias of acf()->cache->enable()
330 *
331 * @type function
332 * @date 26/6/17
333 * @since 5.6.0
334 *
335 * @param n/a
336 * @return n/a
337 */
338
339 function acf_enable_cache() {
340
341 return acf()->cache->enable();
342
343 }
344
345
346 /*
347 * acf_isset_cache
348 *
349 * alias of acf()->cache->isset_cache()
350 *
351 * @type function
352 * @date 30/06/2016
353 * @since 5.4.0
354 *
355 * @param n/a
356 * @return n/a
357 */
358
359 function acf_isset_cache( $key = '' ) {
360
361 return acf()->cache->isset_cache( $key );
362
363 }
364
365
366 /*
367 * acf_get_cache
368 *
369 * alias of acf()->cache->get_cache()
370 *
371 * @type function
372 * @date 30/06/2016
373 * @since 5.4.0
374 *
375 * @param n/a
376 * @return n/a
377 */
378
379 function acf_get_cache( $key = '' ) {
380
381 return acf()->cache->get_cache( $key );
382
383 }
384
385
386 /*
387 * acf_set_cache
388 *
389 * alias of acf()->cache->set_cache()
390 *
391 * @type function
392 * @date 30/06/2016
393 * @since 5.4.0
394 *
395 * @param n/a
396 * @return n/a
397 */
398
399 function acf_set_cache( $key = '', $data ) {
400
401 return acf()->cache->set_cache( $key, $data );
402
403 }
404
405
406 /*
407 * acf_set_cache_reference
408 *
409 * alias of acf()->cache->set_cache_reference()
410 *
411 * @type function
412 * @date 30/06/2016
413 * @since 5.4.0
414 *
415 * @param n/a
416 * @return n/a
417 */
418
419 function acf_set_cache_reference( $key = '', $reference = '' ) {
420
421 return acf()->cache->set_cache_reference( $key, $reference );
422
423 }
424
425
426 /*
427 * acf_delete_cache
428 *
429 * alias of acf()->cache->delete_cache()
430 *
431 * @type function
432 * @date 30/06/2016
433 * @since 5.4.0
434 *
435 * @param n/a
436 * @return n/a
437 */
438
439 function acf_delete_cache( $key = '' ) {
440
441 return acf()->cache->delete_cache( $key );
442
443 }
444
445 ?>