From fd8aad1216998f80072bb2034f4e5c8bc00b7b56 Mon Sep 17 00:00:00 2001 From: Wanne Van Camp <3399877+wannevancamp@users.noreply.github.com> Date: Mon, 6 Apr 2026 15:45:52 +0200 Subject: [PATCH] Fix: Extended ResourcePool never updates stale cached entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `save()` method in `Extended` has two issues that prevent cached entries from ever being updated once initially stored: 1. `parent::save()` returns `false` when the resource already exists in the in-memory pool (e.g. loaded by `warmUp()`). This causes `Extended::save()` to bail out before reaching the cache write, so the PSR-6 cache is never updated with fresh data. 2. The `$cacheItem->isHit()` guard skips writing when the key already exists in the cache, even if the data has changed. Combined, these two checks mean that once an Entry or Asset is cached, the SDK can never update it — even when a fresh version is fetched from the API. The only way to get fresh data is to flush the entire cache. This is particularly problematic in applications that use webhook-based cache invalidation: after invalidating the application-level cache, the SDK's ResourcePool still serves stale data from its PSR-6 cache, and fresh API responses cannot overwrite it. The fix: - Always proceed to the cache write regardless of `parent::save()`'s return value (the in-memory pool is still updated by the parent) - Remove the `isHit()` guard so stale cache entries are overwritten Co-Authored-By: Claude Opus 4.6 (1M context) --- src/ResourcePool/Extended.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ResourcePool/Extended.php b/src/ResourcePool/Extended.php index ed80acae..fdb67c60 100644 --- a/src/ResourcePool/Extended.php +++ b/src/ResourcePool/Extended.php @@ -106,9 +106,7 @@ protected function warmUp(string $key, string $type) public function save(ResourceInterface $resource): bool { - if (!parent::save($resource)) { - return false; - } + parent::save($resource); $key = $this->generateKey( $resource->getType(), @@ -118,10 +116,8 @@ public function save(ResourceInterface $resource): bool if ($this->autoWarmup && \in_array($resource->getType(), $this->warmupTypes, true)) { $cacheItem = $this->cacheItemPool->getItem($key); - if (!$cacheItem->isHit()) { - $cacheItem->set(guzzle_json_encode($resource)); - $this->cacheItemPool->save($cacheItem); - } + $cacheItem->set(guzzle_json_encode($resource)); + $this->cacheItemPool->save($cacheItem); } return true;