Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ abstract class AbstractRequest
/** @var array Tags to be used when inserting to cache */
protected array $cacheTags = [];

public function getCacheTags(): array
Comment thread
jwadhams marked this conversation as resolved.
{
return $this->cacheTags;
}

/** @var string Request method, for use in toGuzzle */
protected string $method = 'POST';

Expand Down Expand Up @@ -317,7 +322,7 @@ protected function getGuzzleClient(): Client

public function purgeCache(): self
{
Cache::tags($this->cacheTags)->forget($this->cacheKey());
Cache::tags($this->getCacheTags())->forget($this->cacheKey());
return $this;
}

Expand All @@ -338,7 +343,7 @@ protected function writeResponseToCache(): void
// so we flatten the body to strings then rehydrate the Response class manually
// Note, when the format of the cached value changes, you have to update CACHE_KEY_SEED
// So that previous cache entries with incompatible cached data are not read by responseFromCache
Cache::tags($this->cacheTags)->put(
Cache::tags($this->getCacheTags())->put(
$this->cacheKey(),
[
'logs' => $this->sentLogs,
Expand All @@ -363,7 +368,7 @@ protected function responseFromCache(): ?Response

// Note, when the format of $fromCache changes, you have to update CACHE_KEY_SEED
// So that previous cache entries with incompatible cached data are not read by responseFromCache
$fromCache = Cache::tags($this->cacheTags)->get($this->cacheKey());
$fromCache = Cache::tags($this->getCacheTags())->get($this->cacheKey());
if ($fromCache) {
$this->sentLogs = array_map(
fn ($filename) => Str::contains($filename, '/')
Expand Down Expand Up @@ -396,7 +401,7 @@ public function cacheKey(): string

public function canBeFulfilledByCache(): bool
{
return Cache::tags($this->cacheTags)->has($this->cacheKey());
return Cache::tags($this->getCacheTags())->has($this->cacheKey());
}

public function isFromCache(): bool
Expand Down
8 changes: 4 additions & 4 deletions app/AbstractUseStaleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function responseFromCache(): ?Response
{
$cachedResponse = parent::responseFromCache();
if ($cachedResponse && $this->needsRefresh()) {
Cache::tags($this->cacheTags)->put(
Cache::tags($this->getCacheTags())->put(
$this->refreshCacheKey(),
'Wait between refreshes',
$this->waitBetweenRefreshes(),
Expand All @@ -44,7 +44,7 @@ protected function responseFromCache(): ?Response
protected function writeResponseToCache(): void
{
if ($this->shouldWriteResponseToCache()) {
Cache::tags($this->cacheTags)->put($this->refreshCacheKey(), 'refresh after', $this->refreshAfter());
Cache::tags($this->getCacheTags())->put($this->refreshCacheKey(), 'refresh after', $this->refreshAfter());
}
parent::writeResponseToCache();
}
Expand All @@ -63,12 +63,12 @@ public function refreshCacheKey(): string

public function needsRefresh(): bool
{
return !Cache::tags($this->cacheTags)->has($this->refreshCacheKey());
return !Cache::tags($this->getCacheTags())->has($this->refreshCacheKey());
}

public function refreshOnNextRequest(): self
{
Cache::tags($this->cacheTags)->forget($this->refreshCacheKey());
Cache::tags($this->getCacheTags())->forget($this->refreshCacheKey());
return $this;
}

Expand Down
3 changes: 1 addition & 2 deletions app/Testing/RequestClassAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ protected static function mockRequestCachedResponse(
array $headers = [],
array $logs = [],
): void {
$tags = getProperty($request, 'cacheTags');
Cache::tags($tags)->put($request->cacheKey(), [
Cache::tags($request->getCacheTags())->put($request->cacheKey(), [
'logs' => $logs,
'response' => [$status, $headers, $body],
]);
Expand Down