PluginProbe
WebTotem Security / 2.4.31
WebTotem Security v2.4.31
3.0.2 3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 All 110 releases
← All changes | lib/Cache.php +6 -9 3.0.22.4.31 View file →
@@ -10,9 +10,9 @@
10 10 * WebTotem Cache class for Wordpress.
11 11 */
12 12 class WebTotemCache {
13 13
14 - const WTOTEM_CACHE_STORAGE_TIME = 5; // cache storage time in minutes
14 + const WTOTEM_CACHE_STORAGE_TIME = 3; // cache storage time in minutes
15 15 /**
16 16 * Save multiple some data to cache.
17 17 *
18 18 * @param array $data
@@ -21,28 +21,25 @@
21 21 * The data belongs to this host.
22 22 * @param string $storage_time
23 23 * Cache storage time in minutes.
24 24 *
25 - * @return array
25 + * @return bool
26 26 * Returns TRUE after saving the data.
27 27 */
28 28 public static function setData(array $data, $host_id, $storage_time = self::WTOTEM_CACHE_STORAGE_TIME) {
29 29
30 30 $cache = json_decode(WebTotemOption::getOption('cache'), true) ?: [];
31 - $result = [];
31 +
32 32 foreach ($data as $key => $value){
33 33 if(!empty($value) and !array_key_exists('errors', $value)){
34 34 $expired = time() + ( $storage_time * 60 );
35 35 $cache[$host_id][$key] = ['data' => $value, 'expired' => $expired];
36 - $result[$key] = true;
37 - } else {
38 - $result[$key] = false;
39 36 }
40 37 }
41 38
42 39 WebTotemOption::setOptions(['cache' => $cache]);
43 40
44 - return $result;
41 + return TRUE;
45 42 }
46 43
47 44 /**
48 45 * Get data from cache.
@@ -58,10 +55,10 @@
58 55 public static function getdata($key, $host_id) {
59 56
60 57 $cache = json_decode(WebTotemOption::getOption('cache'), true) ?: [];
61 58 if(array_key_exists($host_id, $cache) and
62 - array_key_exists($key, $cache[$host_id])
63 - ) { // and $cache[$host_id][$key]['expired'] > time()
59 + array_key_exists($key, $cache[$host_id]) and
60 + $cache[$host_id][$key]['expired'] > time()) {
64 61 return [
65 62 'data' => $cache[$host_id][$key]['data'],
66 63 'remained' => $cache[$host_id][$key]['expired'] - time(),
67 64 ];