-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.php
63 lines (58 loc) · 1.57 KB
/
cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Cache functions for storing of results.
* It's important to store results in cache
* because API connection is expensive operation.
*
* You can substitute this function by your own in
* mu-plugins folder https://wordpress.org/support/article/must-use-plugins/
*
* @package WP REMP Connector
* @author Peter PayteR Gašparík
* @license MIT
* @copyright Copyright (c) 2020
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if(!function_exists('remp_cache_key')) {
/**
* Get formatted cache key
*
* @param string $key
* @return string
*/
function remp_cache_key($key) {
return REMP_CACHE_KEY_PREFIX . '_' . $key . '_' . remp_api_get_token();
}
}
if(!function_exists('remp_cache_get')) {
/**
* Retrieve stored variables from cache by key
*
* @param string $key
* @param string $group
* @param bool $force
* @return bool|mixed
*/
function remp_cache_get($key, $group = REMP_CACHE_KEY_GROUP, $force = false) {
return wp_cache_get(remp_cache_key($key), $group, $force);
}
}
if(!function_exists('remp_cache_set')) {
/**
* Stored variables to the cache
*
* @param string $key
* @param string|array|object $data
* @param string $group
* @param float|int $expire
* @return bool|null
*/
function remp_cache_set($key, $data, $group = REMP_CACHE_KEY_GROUP, $expire = REMP_CACHE_EXPIRATION) {
if(!$expire) {
return null;
}
return wp_cache_set(remp_cache_key($key), $data, $group, $expire);
}
}