| Conditions | 5 |
| Paths | 6 |
| Total Lines | 21 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | public function getCacheDataOrAdd(string $cacheKey, \Closure $closure, array $tags = [], $expiresAfter = null) |
||
| 45 | { |
||
| 46 | $data = null; |
||
| 47 | $cacheItem = $this->getCacheAdapter()->getItem($cacheKey); |
||
| 48 | if ($cacheItem->isHit()) { |
||
| 49 | $data = $cacheItem->get(); |
||
| 50 | } else { |
||
| 51 | $data = $closure(); |
||
| 52 | if ($data) { |
||
| 53 | $cacheItem->set($data); |
||
| 54 | if (!empty($tags)) { |
||
| 55 | $cacheItem->tag($tags); |
||
| 56 | } |
||
| 57 | if ($expiresAfter) { |
||
| 58 | $cacheItem->expiresAfter($expiresAfter); |
||
| 59 | } |
||
| 60 | $this->getCacheAdapter()->save($cacheItem); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | return $data; |
||
| 65 | } |
||
| 67 |