Skip to content

Commit

Permalink
Merge pull request #49588 from nextcloud/bugfix/noid/make-the-cache-c…
Browse files Browse the repository at this point in the history
…heck-use-it

fix(setupcheck): Make the Memcache setupcheck use the cache
  • Loading branch information
nickvergessen authored Dec 2, 2024
2 parents 6aa8113 + 1bcc381 commit 199515f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apps/settings/lib/SetupChecks/MemcacheConfigured.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\Settings\SetupChecks;

use OC\Memcache\Memcached;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand All @@ -20,6 +21,7 @@ public function __construct(
private IL10N $l10n,
private IConfig $config,
private IURLGenerator $urlGenerator,
private ICacheFactory $cacheFactory,
) {
}

Expand Down Expand Up @@ -56,6 +58,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'));
}
}

0 comments on commit 199515f

Please sign in to comment.