Skip to content

Commit b3cf88d

Browse files
committed
Use cache cascade
1 parent d1644d1 commit b3cf88d

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

composer.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cloud-ops/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"craftcms/cms": "^4.6 || ^5.0",
1010
"bref/bref": "^2.4.2",
1111
"bref/extra-php-extensions": "^1.7.2",
12+
"craftcms/yii2-cache-cascade": "^1.0",
1213
"yiisoft/yii2-redis": "^2.0",
1314
"yiisoft/yii2-queue": "^2.3.7",
1415
"aws/aws-sdk-php": "^3.342.6"

packages/cloud-ops/src/AppConfig.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Closure;
66
use Craft;
7+
use craft\cachecascade\CascadeCache;
78
use craft\helpers\App;
9+
use yii\caching\ArrayCache;
810
use yii\redis\Cache as RedisCache;
911

1012
class AppConfig
@@ -71,27 +73,27 @@ private function getCacheConfig(): Closure
7173
$defaultDuration = Craft::$app->getConfig()->getGeneral()->cacheDuration;
7274
$valkey = $this->resolveValkeyEndpoint();
7375

74-
if ($valkey) {
75-
return Craft::createObject([
76-
'class' => RedisCache::class,
77-
'defaultDuration' => $defaultDuration,
78-
'redis' => [
79-
'class' => Redis::class,
80-
'url' => $valkey,
81-
'database' => 0,
82-
],
83-
]);
84-
}
85-
86-
if ($this->tableExists(\craft\db\Table::CACHE)) {
87-
return Craft::createObject([
88-
'class' => \craft\cache\DbCache::class,
89-
'cacheTable' => \craft\db\Table::CACHE,
90-
'defaultDuration' => $defaultDuration,
91-
]);
92-
}
76+
$primaryCache = $valkey ? [
77+
'class' => RedisCache::class,
78+
'defaultDuration' => $defaultDuration,
79+
'redis' => [
80+
'class' => Redis::class,
81+
'url' => $valkey,
82+
'database' => 0,
83+
],
84+
] : [
85+
'class' => \craft\cache\DbCache::class,
86+
'cacheTable' => \craft\db\Table::CACHE,
87+
'defaultDuration' => $defaultDuration,
88+
];
9389

94-
return Craft::createObject(App::cacheConfig());
90+
return Craft::createObject([
91+
'class' => CascadeCache::class,
92+
'caches' => [
93+
$primaryCache,
94+
['class' => ArrayCache::class],
95+
],
96+
]);
9597
};
9698
}
9799

0 commit comments

Comments
 (0)