From 857f1332f3e773eb62f01e89195279acda7a7d04 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 2 Dec 2024 09:02:22 +0100 Subject: [PATCH] fix(setupcheck): Make the Memcache setupcheck use the cache Signed-off-by: Joas Schilling --- .../lib/SetupChecks/MemcacheConfigured.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/apps/settings/lib/SetupChecks/MemcacheConfigured.php b/apps/settings/lib/SetupChecks/MemcacheConfigured.php index d42b0f6729827..049f24ca3b33b 100644 --- a/apps/settings/lib/SetupChecks/MemcacheConfigured.php +++ b/apps/settings/lib/SetupChecks/MemcacheConfigured.php @@ -9,9 +9,11 @@ namespace OCA\Settings\SetupChecks; use OC\Memcache\Memcached; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\Server; use OCP\SetupCheck\ISetupCheck; use OCP\SetupCheck\SetupResult; @@ -56,6 +58,42 @@ public function run(): SetupResult { $this->urlGenerator->linkToDocs('admin-performance') ); } + + $cacheFactory = Server::get(ICacheFactory::class); + if ($cacheFactory->isLocalCacheAvailable()) { + $random = random_bytes(64); + $local = $cacheFactory->createLocal('setupcheck.local'); + try { + $local->set('test', $random); + $local2 = $cacheFactory->createLocal('setupcheck.local'); + $actual = $local2->get('test'); + $local->remove('test'); + } catch (\Throwable) { + $actual = null; + } + + if ($actual !== $random) { + return SetupResult::error($this->l10n->t('Failed to write and read a value from local cache.')); + } + } + + if ($cacheFactory->isAvailable()) { + $random = random_bytes(64); + $distributed = $cacheFactory->createDistributed('setupcheck'); + try { + $distributed->set('test', $random); + $distributed2 = $cacheFactory->createDistributed('setupcheck'); + $actual = $distributed2->get('test'); + $distributed->remove('test'); + } catch (\Throwable) { + $actual = null; + } + + if ($actual !== $random) { + return SetupResult::error($this->l10n->t('Failed to write and read a value from distributed cache.')); + } + } + return SetupResult::success($this->l10n->t('Configured')); } }