guzzle-cache-middleware icon indicating copy to clipboard operation
guzzle-cache-middleware copied to clipboard

"X-Kevinrob-Cache: MISS" although response is from cache

Open rincler opened this issue 4 years ago • 1 comments

Hi!

I have two layers of cache: memory and redis:

...
$stack->push(
  new CacheMiddleware(new GreedyCacheStrategy(new VolatileRuntimeStorage(), 0)),
  'identity-map'
);

$stack->push(
  new CacheMiddleware(new GreedyCacheStrategy(new Psr16CacheStorage($redisCache), 60)),
  'cache'
);
...

Suggest we have cached response in redis. We make $client->request(). I expect: X-Kevinrob-Cache: HIT I see: X-Kevinrob-Cache: MISS

redis middleware set X-Kevinrob-Cache to HIT in https://github.com/Kevinrob/guzzle-cache-middleware/blob/57c579392ef24d6afe72a00ccd73f09ae35a9d24/src/CacheMiddleware.php#L154, but then memory middleware set X-Kevinrob-Cache to MISS in https://github.com/Kevinrob/guzzle-cache-middleware/blob/57c579392ef24d6afe72a00ccd73f09ae35a9d24/src/CacheMiddleware.php#L223

Maybe need to check X-Kevinrob-Cache header before set it to MISS ?

rincler avatar Apr 20 '21 10:04 rincler

You can use ChainCache for using multiple cache storage. But we can change for checking the presence of the header before setting it! Would you like to make a PR about this?

Kevinrob avatar Jul 04 '21 16:07 Kevinrob