1 | <?php |
||
15 | abstract class Storage implements \ArrayAccess |
||
16 | { |
||
17 | /** |
||
18 | * Determine if an item exists in the cache. |
||
19 | * |
||
20 | * @param $key |
||
21 | * |
||
22 | * @return bool |
||
23 | */ |
||
24 | public function has($key) |
||
28 | |||
29 | /** |
||
30 | * Determine if an item exists in the cache. |
||
31 | * |
||
32 | * Enables you to use: isset($storage[$key]) |
||
33 | * |
||
34 | * @param $offset |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | public function offsetExists($offset) |
||
42 | |||
43 | /** |
||
44 | * Get an item from the cache. |
||
45 | * |
||
46 | * <code> |
||
47 | * // Get an item from the cache storage |
||
48 | * $name = Cache::storage('name'); |
||
49 | * |
||
50 | * // Return a default value if the requested item isn't cached |
||
51 | * $name = Cache::get('name', 'Robin'); |
||
52 | * </code> |
||
53 | * |
||
54 | * @param $key |
||
55 | * @param null $default |
||
56 | * |
||
57 | * @return mixed|null |
||
58 | */ |
||
59 | public function get($key, $default = null) |
||
63 | |||
64 | /** |
||
65 | * Get an item from the cache. |
||
66 | * |
||
67 | * Enables you to use: $storage[$key] |
||
68 | * |
||
69 | * <code> |
||
70 | * // Get an item from the cache storage |
||
71 | * $name = Cache::storage()['name']; |
||
72 | * </code> |
||
73 | * |
||
74 | * @param $offset |
||
75 | * |
||
76 | * @return mixed|null |
||
77 | */ |
||
78 | public function offsetGet($offset) |
||
82 | |||
83 | /** |
||
84 | * Retrieve an item from the cache storage. |
||
85 | * |
||
86 | * @param string $key |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | abstract protected function retrieve($key); |
||
91 | |||
92 | /** |
||
93 | * Write an item to the cache for a given number of minutes. |
||
94 | * |
||
95 | * <code> |
||
96 | * // Put an item in the cache for 15 minutes |
||
97 | * Cache::put('name', 'Robin', 15); |
||
98 | * </code> |
||
99 | * |
||
100 | * @param string $key |
||
101 | * @param mixed $value |
||
102 | * @param int $minutes |
||
103 | * |
||
104 | * @return void |
||
105 | */ |
||
106 | abstract public function put($key, $value, $minutes); |
||
107 | |||
108 | /** |
||
109 | * Write an item to the cache for indefinite-term storage. |
||
110 | * |
||
111 | * Enables you to use: $storage[$key] = $value; |
||
112 | * |
||
113 | * @param $key |
||
114 | * @param $value |
||
115 | */ |
||
116 | public function offsetSet($key, $value) |
||
120 | |||
121 | /** |
||
122 | * Get an item from the cache, or cache and return the default value. |
||
123 | * |
||
124 | * <code> |
||
125 | * // Get an item from the cache, or cache a value for 15 minutes |
||
126 | * $name = Cache::remember('name', 'Robin', 15); |
||
127 | * |
||
128 | * // Use a closure for deferred execution |
||
129 | * $count = Cache::remember('count', function () { return User::count(); }, 15); |
||
130 | * </code> |
||
131 | * |
||
132 | * @param string $key |
||
133 | * @param mixed $default |
||
134 | * @param int $minutes |
||
135 | * @param string $function |
||
136 | * |
||
137 | * @return mixed |
||
138 | */ |
||
139 | public function remember($key, $default, $minutes, $function = 'put') |
||
149 | |||
150 | /** |
||
151 | * Write an item to the cache for indefinite-term storage. |
||
152 | * |
||
153 | * @param $key |
||
154 | * @param $value |
||
155 | * |
||
156 | * @return mixed Depends on implementation |
||
157 | */ |
||
158 | abstract public function forever($key, $value); |
||
159 | |||
160 | /** |
||
161 | * Get an item from the cache, or cache the default value forever. |
||
162 | * |
||
163 | * @param string $key |
||
164 | * @param mixed $default |
||
165 | * |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function sear($key, $default) |
||
172 | |||
173 | /** |
||
174 | * Delete an item from the cache. |
||
175 | * |
||
176 | * @param string $key |
||
177 | * |
||
178 | * @return boolean |
||
179 | */ |
||
180 | abstract public function forget($key); |
||
181 | |||
182 | /** |
||
183 | * Delete an item from the cache. |
||
184 | * |
||
185 | * Enables you to use: unset($storage[$key]); |
||
186 | * |
||
187 | * @param string $key |
||
188 | */ |
||
189 | public function offsetUnset($key) |
||
193 | |||
194 | /** |
||
195 | * Get the expiration time as a UNIX timestamp. |
||
196 | * |
||
197 | * @param int $minutes |
||
198 | * |
||
199 | * @return int |
||
200 | */ |
||
201 | protected static function expiration($minutes) |
||
205 | } |
||
206 |