|
4 | 4 |
|
5 | 5 | use Closure; |
6 | 6 | use Craft; |
7 | | -use craft\cachecascade\CascadeCache; |
| 7 | +use craft\cache\DbCache; |
| 8 | +use craft\db\Table; |
8 | 9 | use craft\helpers\App; |
9 | | -use yii\caching\ArrayCache; |
10 | | -use yii\redis\Cache as RedisCache; |
11 | 10 |
|
12 | 11 | class AppConfig |
13 | 12 | { |
@@ -70,49 +69,15 @@ private function getSessionConfig(): Closure |
70 | 69 | private function getCacheConfig(): Closure |
71 | 70 | { |
72 | 71 | return function() { |
73 | | - $defaultDuration = Craft::$app->getConfig()->getGeneral()->cacheDuration; |
74 | | - |
75 | | - $valkey = $this->resolveValkeyEndpoint(); |
76 | | - |
77 | | - $primaryCache = $valkey ? [ |
78 | | - 'class' => RedisCache::class, |
79 | | - 'defaultDuration' => $defaultDuration, |
80 | | - 'redis' => [ |
81 | | - 'class' => Redis::class, |
82 | | - 'url' => $valkey, |
83 | | - 'database' => 0, |
84 | | - ], |
85 | | - ] : [ |
86 | | - 'class' => \craft\cache\DbCache::class, |
87 | | - 'cacheTable' => \craft\db\Table::CACHE, |
88 | | - 'defaultDuration' => $defaultDuration, |
89 | | - ]; |
| 72 | + $config = $this->tableExists(Table::CACHE) ? [ |
| 73 | + 'class' => DbCache::class, |
| 74 | + 'cacheTable' => Table::CACHE, |
| 75 | + 'defaultDuration' => Craft::$app->getConfig()->getGeneral()->cacheDuration, |
| 76 | + ] : App::cacheConfig(); |
90 | 77 |
|
91 | | - return Craft::createObject([ |
92 | | - 'class' => CascadeCache::class, |
93 | | - 'caches' => [ |
94 | | - $primaryCache, |
95 | | - ['class' => ArrayCache::class], |
96 | | - ], |
97 | | - ]); |
98 | | - }; |
99 | | - } |
100 | | - |
101 | | - private function resolveValkeyEndpoint(): ?string |
102 | | - { |
103 | | - $srv = App::env('CRAFT_CLOUD_CACHE_SRV'); |
104 | | - |
105 | | - if ($srv) { |
106 | | - $record = dns_get_record($srv, DNS_SRV); |
107 | | - |
108 | | - if (!empty($record)) { |
109 | | - return 'redis://' . $record[0]['target'] . ':' . $record[0]['port']; |
110 | | - } |
111 | | - } |
| 78 | + return Craft::createObject($config); |
112 | 79 |
|
113 | | - // Deprecated. We are moving to CRAFT_CLOUD_CACHE_SRV for both Fargate and ECS. |
114 | | - // Once every website is moved over, we can disregared this fallback. |
115 | | - return App::env('CRAFT_CLOUD_REDIS_URL'); |
| 80 | + }; |
116 | 81 | } |
117 | 82 |
|
118 | 83 | private function getQueueConfig(): Closure |
|
0 commit comments