PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / Cache.php

Cache.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/Cache.php

59 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services;
4
5 use FluentCart\App\App;
6
7 class Cache
8 {
9
10 public static function get($key, $callback = false, $expire = 3600)
11 {
12 $key = static::getKey($key);
13
14 $value = wp_cache_get($key, static::getGroupName());
15
16 if ($value !== false) {
17 return $value;
18 }
19
20 if ($callback) {
21 $value = $callback();
22 if ($value !== null) {
23 static::set($key, $value, $expire);
24 }
25 }
26
27 return $value;
28 }
29
30 public static function forget($key): bool
31 {
32 return wp_cache_delete(static::getKey($key), static::getGroupName());
33 }
34
35 public static function set($key, $value, $expire = 3600): bool
36 {
37 return wp_cache_set(static::getKey($key), $value, static::getGroupName(), $expire);
38 }
39
40 public static function update($key, $value, $expire = 3600): bool
41 {
42 return static::set(static::getKey($key), $value, $expire);
43 }
44
45 private static function getKey(string $key): string
46 {
47 return static::getKeyPrefix() . '_' . $key;
48 }
49
50 private static function getKeyPrefix()
51 {
52 return App::config()->get('slug');
53 }
54
55 private static function getGroupName(): string
56 {
57 return 'fluent-cart';
58 }
59 }