fix(Memcache): ensure global prefix depends on enabled apps

- ensure the prefix is changed when an app is (dis)enabled
- ensure the app ids are included in the hash instead of only the
  version numbers
- ensure hash is deterministic by always use the same order.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2025-10-27 16:18:24 +01:00 committed by backportbot[bot]
parent 8bba3e31a1
commit 866bc8e239

View file

@ -116,13 +116,16 @@ class Factory implements ICacheFactory {
$versions = [];
if ($config->getValue('installed', false)) {
$appConfig = \OCP\Server::get(IAppConfig::class);
$versions = $appConfig->getAppInstalledVersions();
// only get the enabled apps to clear the cache in case an app is enabled or disabled (e.g. clear routes)
$versions = $appConfig->getAppInstalledVersions(true);
ksort($versions);
}
$versions['core'] = implode('.', $this->serverVersion->getVersion());
// Include instanceid in the prefix, in case multiple instances use the same cache (e.g. same FPM pool)
$instanceid = $config->getValue('instanceid');
$this->globalPrefix = hash('xxh128', $instanceid . implode(',', $versions));
$installedApps = implode(',', array_keys($versions)) . implode(',', array_values($versions));
$this->globalPrefix = hash('xxh128', $instanceid . $installedApps);
}
return $this->globalPrefix;
}