Skip to content

Commit 6ccd54a

Browse files
committed
Remove useless try/catch in the CachedTrait.
1 parent c99a148 commit 6ccd54a

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/Cache/CachedTrait.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,18 @@ private function getCached(string $cacheKey, callable $getValue)
3333

3434
try {
3535
$cacheItem = $this->cacheItemPool->getItem($cacheKey);
36-
37-
if ($cacheItem->isHit()) {
38-
return $this->localCache[$cacheKey] = $cacheItem->get();
39-
}
4036
} catch (CacheException $e) {
41-
//do nothing
37+
return $this->localCache[$cacheKey] = $getValue();
4238
}
4339

44-
$value = $getValue();
45-
46-
if (!isset($cacheItem)) {
47-
return $this->localCache[$cacheKey] = $value;
40+
if ($cacheItem->isHit()) {
41+
return $this->localCache[$cacheKey] = $cacheItem->get();
4842
}
4943

50-
try {
51-
$cacheItem->set($value);
52-
$this->cacheItemPool->save($cacheItem);
53-
} catch (CacheException $e) {
54-
// do nothing
55-
}
44+
$value = $getValue();
45+
46+
$cacheItem->set($value);
47+
$this->cacheItemPool->save($cacheItem);
5648

5749
return $this->localCache[$cacheKey] = $value;
5850
}

0 commit comments

Comments
 (0)