From e3c1eb69357fe92783fb75167f9d36f92af6113c 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 | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/settings/lib/SetupChecks/MemcacheConfigured.php b/apps/settings/lib/SetupChecks/MemcacheConfigured.php index 98192f6289e1b..da9fbdf684c14 100644 --- a/apps/settings/lib/SetupChecks/MemcacheConfigured.php +++ b/apps/settings/lib/SetupChecks/MemcacheConfigured.php @@ -25,6 +25,7 @@ */ namespace OCA\Settings\SetupChecks; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; @@ -36,6 +37,7 @@ public function __construct( private IL10N $l10n, private IConfig $config, private IURLGenerator $urlGenerator, + private ICacheFactory $cacheFactory, ) { } @@ -72,6 +74,41 @@ public function run(): SetupResult { $this->urlGenerator->linkToDocs('admin-performance') ); } + + if ($this->cacheFactory->isLocalCacheAvailable()) { + $random = random_bytes(64); + $local = $this->cacheFactory->createLocal('setupcheck.local'); + try { + $local->set('test', $random); + $local2 = $this->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 ($this->cacheFactory->isAvailable()) { + $random = random_bytes(64); + $distributed = $this->cacheFactory->createDistributed('setupcheck'); + try { + $distributed->set('test', $random); + $distributed2 = $this->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')); } }