1 | <?php |
||
16 | class Cache |
||
17 | { |
||
18 | /*** @var \Metaphore\Store\ValueStoreInterface */ |
||
19 | protected $valueStore; |
||
20 | |||
21 | /*** @var \Metaphore\LockManager */ |
||
22 | protected $lockManager; |
||
23 | |||
24 | /*** @var callable */ |
||
25 | protected $onNoStaleCacheCallable; |
||
26 | |||
27 | /** |
||
28 | * @param \Metaphore\Store\ValueStoreInterface |
||
29 | * @param \Metaphore\Store\LockStoreInterface |
||
30 | * @throws \Metaphore\Exception When value store cannot be used as lock store by default. |
||
31 | */ |
||
32 | public function __construct(ValueStoreInterface $valueStore, LockManager $lockManager = null) |
||
48 | |||
49 | /** |
||
50 | * Caches specified closure/method/function for specified time. |
||
51 | * |
||
52 | * As a third argument - instead of integer - you can pass Ttt object to |
||
53 | * define grace tll and lock ttl (both optional). |
||
54 | * |
||
55 | * @param string |
||
56 | * @param callable |
||
57 | * @param int|\Metaphore\Ttl |
||
58 | * @param callable |
||
59 | */ |
||
60 | public function cache($key, callable $cachedCallable, $ttl, callable $onNoStaleCacheCallable = null) |
||
104 | |||
105 | /** |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function delete($key) |
||
112 | |||
113 | /** |
||
114 | * @return Value |
||
115 | */ |
||
116 | public function getValue($key) |
||
126 | |||
127 | /** |
||
128 | * Sets result. Does not use anti-dogpile-effect mechanism. Use cache() instead for this. |
||
129 | * |
||
130 | * @param string |
||
131 | * @param mixed |
||
132 | * @param int|\Metaphore\Ttl |
||
133 | */ |
||
134 | public function setResult($key, $result, $ttl) |
||
145 | |||
146 | /** |
||
147 | * @param callable |
||
148 | */ |
||
149 | public function onNoStaleCache(callable $onNoStaleCacheCallable) |
||
153 | |||
154 | /** |
||
155 | * @return ValueStoreInterface |
||
156 | */ |
||
157 | public function getValueStore() |
||
161 | |||
162 | /** |
||
163 | * @return LockManager |
||
164 | */ |
||
165 | public function getLockManager() |
||
169 | } |
||
170 |