Skip to content
Open
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
10 changes: 0 additions & 10 deletions src/services/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,6 @@ public function stopCollectingCacheInfo(): array
return [null, null];
}

// Only use the duration if it's less than the cacheDuration config setting
$generalConfig = Craft::$app->getConfig()->getGeneral();
if ($generalConfig->cacheDuration) {
if ($duration) {
$duration = min($duration, $generalConfig->cacheDuration);
} else {
$duration = $generalConfig->cacheDuration;
}
}

$dep = new TagDependency([
'tags' => array_keys($tags),
]);
Expand Down
17 changes: 8 additions & 9 deletions src/services/TemplateCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function endTemplateCache(string $key, bool $global, ?string $duration, m
}

[$dep, $maxDuration] = Craft::$app->getElements()->stopCollectingCacheInfo();
$defaultDuration = Craft::$app->getConfig()->getGeneral()->cacheDuration;
$maxDuration = min($maxDuration, $defaultDuration);

if ($withResources) {
$view = Craft::$app->getView();
Expand All @@ -174,21 +176,18 @@ public function endTemplateCache(string $key, bool $global, ?string $duration, m
$saveCache = !StringHelper::contains(stripslashes($body), 'assets/generate-transform');

if ($saveCache) {
if (!$dep) {
$dep = new TagDependency();
}
$dep = $dep ?? new TagDependency();

// Always add a `template` tag
$dep->tags[] = 'template';

$cacheInfo = [
'tags' => $dep->tags,
];

if ($maxDuration) {
$expiryDate = DateTimeHelper::now()->modify("+$maxDuration seconds");
$cacheInfo = [
'tags' => $dep->tags,
'expiryDate' => DateTimeHelper::toIso8601($expiryDate),
];
} else {
$cacheInfo = $dep->tags;
$cacheInfo['expiryDate'] = DateTimeHelper::toIso8601($expiryDate);
}

$cacheValue = [$body, $cacheInfo];
Expand Down
Loading