Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Apr 4, 2024
1 parent fb34459 commit de9cfae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
14 changes: 2 additions & 12 deletions src/services/CacheRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,6 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool
return true;
}

/**
* Returns whether the site URI is expired.
*
* @since 4.8.0
*/
public function getIsExpiredSiteUri(SiteUriModel $siteUri): bool
{
return Blitz::$plugin->expireCache->getExpiredCacheId($siteUri) !== false;
}

/**
* Returns whether this is a cached include without memoizing the result,
* which would disrupt the local cache generator.
Expand Down Expand Up @@ -680,9 +670,9 @@ private function prepareResponse(Response $response, SiteUriModel $siteUri, bool
{
$cacheControlHeader = Blitz::$plugin->settings->cacheControlHeader;

if ($this->getIsExpiredSiteUri($siteUri)) {
if (Blitz::$plugin->expireCache->getIsExpiredSiteUri($siteUri)) {
$cacheControlHeader = Blitz::$plugin->settings->cacheControlHeaderExpired;
Blitz::$plugin->refreshCache->refreshExpiredSiteUri($siteUri);
Blitz::$plugin->refreshCache->refreshExpiredSiteUris([$siteUri]);
}

$headers = $response->getHeaders();
Expand Down
9 changes: 5 additions & 4 deletions src/services/ExpireCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ public function getExpiredCacheIds(): array
}

/**
* Returns an expired cache ID with the provided site URI.
* Returns whether the site URI is expired.
*
* @since 4.15.0
*/
public function getExpiredCacheId(SiteUriModel $siteUri): int|false|null
public function getIsExpiredSiteUri(SiteUriModel $siteUri): bool
{
return CacheRecord::find()
->select('id')
->where(['<=', 'expiryDate', Db::prepareDateForDb('now')])
->andWhere($siteUri->toArray())
->scalar();
->exists();
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/services/RefreshCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,13 @@ public function refreshSite(int $siteId): void
}

/**
* Refreshes an expired site URI.
* Refreshes expired site URIs.
*/
public function refreshExpiredSiteUri(SiteUriModel $siteUri): void
public function refreshExpiredSiteUris(array $siteUris): void
{
$cacheId = Blitz::$plugin->expireCache->getExpiredCacheId($siteUri);

if (empty($cacheId)) {
return;
}
$cacheIds = SiteUriHelper::getCacheIdsFromSiteUris($siteUris);
$this->addCacheIds($cacheIds);

$this->addCacheIds([$cacheId]);
$this->refreshExpired();
}

Expand All @@ -482,9 +478,11 @@ public function refreshExpiredSiteUri(SiteUriModel $siteUri): void
public function refreshExpiredCache(): void
{
$this->batchMode = true;

$cacheIds = Blitz::$plugin->expireCache->getExpiredCacheIds();
$this->addCacheIds($cacheIds);
$this->addExpiredElements();

$this->refreshExpired();
}

Expand All @@ -494,7 +492,9 @@ public function refreshExpiredCache(): void
public function refreshExpiredElements(): void
{
$this->batchMode = true;

$this->addExpiredElements();

$this->refreshExpired();
}

Expand Down

0 comments on commit de9cfae

Please sign in to comment.