Skip to content

Commit cd03004

Browse files
authored
Merge pull request #25 from netlogix/feat/cache-control-no-store-prevents-in-memory-caching
2 parents 5e4cd5e + fb5d723 commit cd03004

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Classes/Service/ConsumerBackend.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Psr\Http\Message\ResponseInterface;
2828
use Psr\Http\Message\UriInterface;
2929

30+
use function strtolower;
31+
3032
/**
3133
* @Flow\Scope("singleton")
3234
*/
@@ -256,10 +258,18 @@ protected function requestJson(Uri $uri): PromiseInterface
256258
$uriString = (string)$uri;
257259

258260
$headers = $this->getRequestHeaders($uriString);
261+
259262
$headersForCacheIdentifier = [];
263+
$storeResponse = true;
264+
260265
foreach ($headers as $key => $value) {
266+
$key = strtolower($key);
267+
if ($key === 'cache-control' && strtolower($value) === 'no-store') {
268+
$storeResponse = false;
269+
}
261270
$headersForCacheIdentifier[] = sprintf('%s: %s', $key, $value);
262271
}
272+
263273
$cacheIdentifier = md5(serialize($headersForCacheIdentifier) . '|' . $uriString);
264274

265275
if ($this->requestsCache->has($cacheIdentifier)) {
@@ -269,8 +279,10 @@ protected function requestJson(Uri $uri): PromiseInterface
269279
} else {
270280
$response = $this
271281
->fetch($uri, $headers)
272-
->then(function(string $result) use ($cacheIdentifier) {
273-
$this->requestsCache->set($cacheIdentifier, $result);
282+
->then(function(string $result) use ($cacheIdentifier, $storeResponse) {
283+
if (!$storeResponse) {
284+
$this->requestsCache->set($cacheIdentifier, $result);
285+
}
274286
return $result;
275287
});
276288
}

0 commit comments

Comments
 (0)