Skip to content

Remove useless try/catch in the CachedTrait #1931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/Cache/CachedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,18 @@ private function getCached(string $cacheKey, callable $getValue)

try {
$cacheItem = $this->cacheItemPool->getItem($cacheKey);

if ($cacheItem->isHit()) {
return $this->localCache[$cacheKey] = $cacheItem->get();
}
} catch (CacheException $e) {
//do nothing
return $this->localCache[$cacheKey] = $getValue();
}

$value = $getValue();

if (!isset($cacheItem)) {
return $this->localCache[$cacheKey] = $value;
if ($cacheItem->isHit()) {
return $this->localCache[$cacheKey] = $cacheItem->get();
}

try {
$cacheItem->set($value);
$this->cacheItemPool->save($cacheItem);
} catch (CacheException $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only copying exciting code in the previous pr so I am not sure of the original author's thoughts, but you are now keeping the exception handling above but removing this one. Should we be consistent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no chance of CacheException being thrown here. The original author (i.e. myself) was mistaken. 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we all copied without thinking twice 😆

// do nothing
}
$value = $getValue();

$cacheItem->set($value);
$this->cacheItemPool->save($cacheItem);

return $this->localCache[$cacheKey] = $value;
}
Expand Down