Skip to content

Commit 339a84a

Browse files
author
Maelmin Henge
committed
Add cache varying to WSRequest
1 parent e39c565 commit 339a84a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Cache/CacheManager.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ public function invalidateCacheByWSRequest(WSRequest $request): void
175175
private function buildCacheId(WSRequest $request): string
176176
{
177177
return $request->webService . '-' . $request->subService . '-' . $request->action
178-
. md5(
179-
serialize($request->getRequestParams())
180-
);
178+
. md5(serialize($request->getCacheParams()));
181179
}
182180

183181
private function sanitizeArray(array $array): array

src/Request/WSRequest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class WSRequest
1515
*/
1616
private array $options = [];
1717

18+
private array $cacheVaryingParams = [];
19+
1820
public function __construct(
1921
public readonly string $webService,
2022
public readonly string $action,
@@ -155,4 +157,21 @@ public function setTimeout(float $timeout): static
155157

156158
return $this;
157159
}
160+
161+
public function setCacheVaryingParams(array $params): static
162+
{
163+
$this->cacheVaryingParams = $params;
164+
165+
return $this;
166+
}
167+
168+
public function getCacheParams(): array
169+
{
170+
$requestParams = $this->getRequestParams();
171+
$varyingParams = $this->cacheVaryingParams;
172+
ksort($requestParams);
173+
ksort($varyingParams);
174+
175+
return array_merge($requestParams, $varyingParams);
176+
}
158177
}

0 commit comments

Comments
 (0)