| Conditions | 3 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | public function __invoke(Query $query, callable $next): Result |
||
| 25 | { |
||
| 26 | if (!$query instanceof CacheableQuery) { |
||
| 27 | return $next($query); |
||
| 28 | } |
||
| 29 | |||
| 30 | $cachedResult = $this->cachePool->getItem($query->getCacheKey()); |
||
| 31 | if ($cachedResult->isHit()) { |
||
| 32 | return $cachedResult->get(); |
||
| 33 | } |
||
| 34 | |||
| 35 | $cachedResult->set($next($query)) |
||
| 36 | ->expiresAfter($query->getTTL()); |
||
| 37 | |||
| 38 | $this->cachePool->save($cachedResult); |
||
| 39 | |||
| 40 | return $cachedResult->get(); |
||
| 41 | } |
||
| 43 |