| Conditions | 6 |
| Paths | 18 |
| Total Lines | 30 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function getOrSave(string $cacheKey, CacheItemPoolInterface $pool, &$localCache, callable $callback) |
||
| 22 | { |
||
| 23 | if (isset($localCache[$cacheKey])) { |
||
| 24 | return $localCache[$cacheKey]; |
||
| 25 | } |
||
| 26 | |||
| 27 | try { |
||
| 28 | $cacheItem = $pool->getItem($cacheKey); |
||
| 29 | |||
| 30 | if ($cacheItem->isHit()) { |
||
| 31 | return $localCache[$cacheKey] = $cacheItem->get(); |
||
| 32 | } |
||
| 33 | } catch (CacheException $e) { |
||
| 34 | //do nothing |
||
| 35 | } |
||
| 36 | |||
| 37 | $routeName = $callback(); |
||
| 38 | |||
| 39 | if (!isset($cacheItem)) { |
||
| 40 | return $localCache[$cacheKey] = $routeName; |
||
| 41 | } |
||
| 42 | |||
| 43 | try { |
||
| 44 | $cacheItem->set($routeName); |
||
| 45 | $pool->save($cacheItem); |
||
| 46 | } catch (CacheException $e) { |
||
| 47 | // do nothing |
||
| 48 | } |
||
| 49 | |||
| 50 | return $localCache[$cacheKey] = $routeName; |
||
| 51 | } |
||
| 53 |