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