Skip to content

Commit

Permalink
fix(setupcheck): Make the Memcache setupcheck use the cache
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Dec 2, 2024
1 parent c3b336d commit 857f133
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apps/settings/lib/SetupChecks/MemcacheConfigured.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'));
}
}

0 comments on commit 857f133

Please sign in to comment.