Skip to content

Commit 0905d88

Browse files
committed
fix: Don't throw on cache errors
Broken caches should not lead to an exception
1 parent c3243f5 commit 0905d88

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

Classes/Domain/Model/ResourceProxyIterator.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33

44
namespace Netlogix\JsonApiOrg\Consumer\Domain\Model;
55

6+
use Countable;
67
use Generator;
8+
use IteratorAggregate;
79
use Neos\Cache\Frontend\VariableFrontend;
810
use Neos\Flow\Cache\CacheManager;
11+
use Neos\Flow\Log\ThrowableStorageInterface;
912
use Neos\Flow\Utility\Now;
1013
use Psr\Http\Message\UriInterface;
14+
use Throwable;
1115

12-
class ResourceProxyIterator implements \IteratorAggregate, \Countable
16+
class ResourceProxyIterator implements IteratorAggregate, Countable
1317
{
18+
protected ?ThrowableStorageInterface $throwableStorage;
19+
1420
/**
1521
* @var VariableFrontend
1622
*/
@@ -61,6 +67,11 @@ public function injectNow(Now $now)
6167
$this->now = $now;
6268
}
6369

70+
public function injectThrowableStorage(ThrowableStorageInterface $throwableStorage): void
71+
{
72+
$this->throwableStorage = $throwableStorage;
73+
}
74+
6475
public function initialize(callable $convertResourceDefinitionToResourceProxy): self
6576
{
6677
$result = $this->jsonResult ?? [];
@@ -139,14 +150,25 @@ public function saveToCache(int $lifetime, string ...$tags): self
139150
'eTag' => $eTag,
140151
];
141152

142-
$this->cache->set($identifier, $cacheData, $tags, $lifetime);
153+
try {
154+
$this->cache->set($identifier, $cacheData, $tags, $lifetime);
155+
} catch (Throwable $t) {
156+
$this->throwableStorage?->logThrowable($t);
157+
}
158+
143159
return $this;
144160
}
145161

146162
public function loadFromCache(): self
147163
{
148164
$identifier = sha1($this->uri);
149-
$cacheData = $this->cache->get($identifier);
165+
$cacheData = null;
166+
try {
167+
$cacheData = $this->cache->get($identifier);
168+
} catch (Throwable $t) {
169+
$this->throwableStorage?->logThrowable($t);
170+
}
171+
150172
if (is_array($cacheData)) {
151173
$this->jsonResult = $cacheData['jsonResult'] ?? null;
152174
$this->eTag = $cacheData['eTag'] ?? '';

0 commit comments

Comments
 (0)