1 | <?php |
||
13 | class CacheableService |
||
14 | { |
||
15 | /** |
||
16 | * Cache manager object. |
||
17 | * |
||
18 | * @var \Illuminate\Contracts\Cache\Store |
||
19 | */ |
||
20 | protected $cache; |
||
21 | |||
22 | /** |
||
23 | * Runtime cache. |
||
24 | * |
||
25 | * @var \Illuminate\Cache\ArrayStore |
||
26 | */ |
||
27 | protected $runtimeCache; |
||
28 | |||
29 | /** |
||
30 | * Class constructor. |
||
31 | * |
||
32 | * @param \Illuminate\Cache\CacheManager $cache |
||
33 | * @param \Illuminate\Cache\ArrayStore $runtimeCache |
||
34 | */ |
||
35 | public function __construct(CacheManager $cache, ArrayStore $runtimeCache) |
||
36 | { |
||
37 | $this->cache = $cache->store()->getStore(); |
||
38 | $this->runtimeCache = $runtimeCache; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Just an alias of wrap() method. |
||
43 | * |
||
44 | * @param mixed $repository |
||
45 | * |
||
46 | * @return \Suitmedia\Cacheable\CacheableDecorator |
||
47 | */ |
||
48 | public function build($repository): CacheableDecorator |
||
49 | { |
||
50 | return $this->wrap($repository); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Flush cache. |
||
55 | * |
||
56 | * @param mixed $tags |
||
57 | * |
||
58 | * @throws ErrorException |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | public function flush($tags = null): void |
||
67 | |||
68 | /** |
||
69 | * Get runtime cached object. |
||
70 | * |
||
71 | * @param mixed $tags |
||
72 | * @param string $key |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | protected function getRuntimeCache($tags, $key) |
||
80 | |||
81 | /** |
||
82 | * Retrieve cached items. |
||
83 | * |
||
84 | * @param mixed $tags |
||
85 | * @param string $key |
||
86 | * @param int $duration |
||
87 | * @param Closure $callable |
||
88 | * |
||
89 | * @throws ErrorException |
||
90 | * |
||
91 | * @return mixed |
||
92 | */ |
||
93 | public function retrieve($tags, $key, $duration, Closure $callable) |
||
109 | |||
110 | /** |
||
111 | * Set runtime cache object. |
||
112 | * |
||
113 | * @param mixed $tags |
||
114 | * @param string $key |
||
115 | * @param mixed $value |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | protected function setRuntimeCache($tags, $key, $value): void |
||
123 | |||
124 | /** |
||
125 | * Get tagged cache object. |
||
126 | * |
||
127 | * @param Store $cache |
||
128 | * @param mixed $tags |
||
129 | * |
||
130 | * @throws ErrorException |
||
131 | * |
||
132 | * @return \Illuminate\Cache\TaggedCache|TaggableStore |
||
133 | */ |
||
134 | protected function taggedCache(Store $cache, $tags) |
||
142 | |||
143 | /** |
||
144 | * Build CacheableDecorator and wrap the given class name |
||
145 | * or repository object. |
||
146 | * |
||
147 | * @param mixed $repository |
||
148 | * |
||
149 | * @return \Suitmedia\Cacheable\CacheableDecorator |
||
150 | */ |
||
151 | public function wrap($repository): CacheableDecorator |
||
159 | |||
160 | /** |
||
161 | * Wrap the given CacheableRepository with a new CacheableDecorator. |
||
162 | * |
||
163 | * @param \Suitmedia\Cacheable\Contracts\CacheableRepository $repository |
||
164 | * |
||
165 | * @return \Suitmedia\Cacheable\CacheableDecorator |
||
166 | */ |
||
167 | protected function wrapWithDecorator(CacheableRepository $repository): CacheableDecorator |
||
171 | } |
||
172 |