1 | <?php |
||
8 | class Cache |
||
9 | { |
||
10 | use ServiceInstances; |
||
11 | |||
12 | const CACHE_BASE_NAME = 'firewall.'; |
||
13 | |||
14 | private $cache; |
||
15 | |||
16 | 49 | public function __construct(CacheManager $cache) |
|
20 | |||
21 | /** |
||
22 | * Cache remember. |
||
23 | * |
||
24 | * @param $model |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | 33 | public function remember($model) |
|
34 | |||
35 | /** |
||
36 | * Make a cache key. |
||
37 | * |
||
38 | * @param $key |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | 49 | public function key($key) |
|
46 | |||
47 | /** |
||
48 | * Check if cache has key. |
||
49 | * |
||
50 | * @param $key |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | 48 | public function has($key) |
|
55 | { |
||
56 | 48 | if ($this->enabled()) { |
|
57 | 48 | return $this->cache->has($this->key($key)); |
|
58 | } |
||
59 | |||
60 | 1 | return false; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Get a value from the cache. |
||
65 | * |
||
66 | * @param $key |
||
67 | * |
||
68 | * @return mixed|null |
||
69 | */ |
||
70 | 23 | public function get($key) |
|
71 | { |
||
72 | 23 | if ($this->enabled()) { |
|
73 | 23 | return $this->cache->get($this->key($key)); |
|
|
|||
74 | } |
||
75 | 1 | } |
|
76 | |||
77 | /** |
||
78 | * Remove an ip address from cache. |
||
79 | * |
||
80 | * @param $key |
||
81 | * |
||
82 | * @return void |
||
83 | */ |
||
84 | 7 | public function forget($key) |
|
90 | |||
91 | /** |
||
92 | * Store an item in the cache for a given number of minutes. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @param mixed $value |
||
96 | * @param int|null|bool $minutes |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | 36 | public function put($key, $value, $minutes = null) |
|
106 | |||
107 | /** |
||
108 | * Get cache expire time. |
||
109 | * |
||
110 | * @return int|bool |
||
111 | */ |
||
112 | 49 | public function expireTime() |
|
116 | |||
117 | /** |
||
118 | * Get enabled state. |
||
119 | * |
||
120 | * @return int|bool |
||
121 | */ |
||
122 | 49 | public function enabled() |
|
127 | } |
||
128 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.