1 | <?php |
||
17 | class CacheService implements ServiceInterface |
||
18 | { |
||
19 | /** |
||
20 | * Contains instance of repository. |
||
21 | * |
||
22 | * @var Repository |
||
23 | */ |
||
24 | protected $repository; |
||
25 | |||
26 | /** |
||
27 | * Contains cache repository. |
||
28 | * |
||
29 | * @var \Illuminate\Contracts\Cache\Repository |
||
30 | */ |
||
31 | protected $cache; |
||
32 | |||
33 | /** |
||
34 | * Contains tag for repository model. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $tag; |
||
39 | |||
40 | /** |
||
41 | * Contains cache life time. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $lifetime; |
||
46 | |||
47 | /** |
||
48 | * Contains cache key for given action. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $cacheKey; |
||
53 | |||
54 | /** |
||
55 | * Create a new cache service instance. |
||
56 | * |
||
57 | * @param Application $app |
||
58 | * @param Repository $repository |
||
59 | */ |
||
60 | 120 | public function __construct(Application $app, Repository $repository) |
|
67 | |||
68 | /** |
||
69 | * Execute refresh on cache service and update action on database service. |
||
70 | * |
||
71 | * @param int $identifier |
||
72 | * @param array $attributes |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | 2 | public function update($identifier, array $attributes = []) |
|
82 | |||
83 | /** |
||
84 | * Forget, and store new data into cache. |
||
85 | * |
||
86 | * @param string $caller |
||
87 | * @param array $parameters |
||
88 | * |
||
89 | * @return mixed |
||
90 | */ |
||
91 | 2 | public function refresh($caller, array $parameters = []) |
|
99 | |||
100 | /** |
||
101 | * Generate and return cache key for caller with specified parameters. |
||
102 | * |
||
103 | * @param string $caller |
||
104 | * @param array $parameters |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 20 | public function cacheKey($caller, array $parameters = []) |
|
122 | |||
123 | /** |
||
124 | * Initialize cache repository with specified tag for given model. |
||
125 | * |
||
126 | * @return \Illuminate\Contracts\Cache\Repository |
||
127 | */ |
||
128 | 20 | protected function cache() |
|
132 | |||
133 | /** |
||
134 | * Store data in cache behind caller with specified parameters. |
||
135 | * |
||
136 | * @param string $caller |
||
137 | * @param array $parameters |
||
138 | * |
||
139 | * @return mixed |
||
140 | */ |
||
141 | 20 | public function store($caller, array $parameters = []) |
|
151 | |||
152 | /** |
||
153 | * Execute forget on cache service and delete action on database services. |
||
154 | * |
||
155 | * @param int $identifier |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | 2 | public function delete($identifier) |
|
165 | |||
166 | /** |
||
167 | * Forget data in cache behind caller with specified parameters. |
||
168 | * |
||
169 | * @param string $caller |
||
170 | * @param array $parameters |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | 20 | public function forget($caller, array $parameters = []) |
|
184 | |||
185 | /** |
||
186 | * Dynamicly call method on cache service. |
||
187 | * |
||
188 | * @param string $caller |
||
189 | * @param array $parameters |
||
190 | * |
||
191 | * @return mixed |
||
192 | */ |
||
193 | 20 | public function __call($caller, array $parameters = []) |
|
197 | |||
198 | /** |
||
199 | * Retrieve or store and return data from cache. |
||
200 | * |
||
201 | * @param string $caller |
||
202 | * @param array $parameters |
||
203 | * |
||
204 | * @return mixed |
||
205 | */ |
||
206 | 20 | public function retrieveOrStore($caller, array $parameters = []) |
|
212 | |||
213 | /** |
||
214 | * Return data for given cache key. |
||
215 | * |
||
216 | * @param string $cacheKey |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | 20 | public function retrieve($cacheKey) |
|
228 | |||
229 | /** |
||
230 | * Check if specified cache key exists and has data. |
||
231 | * |
||
232 | * @param string $cacheKey |
||
233 | * |
||
234 | * @return bool |
||
235 | */ |
||
236 | 20 | public function has($cacheKey) |
|
240 | } |
||
241 |