Skip to content

Commit 31146d6

Browse files
Earl0fPuddingkesselb
authored andcommitted
feat: Add memcache_customprefix
Signed-off-by: Martin <31348196+Earl0fPudding@users.noreply.github.com>
1 parent 50f27f3 commit 31146d6

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

config/config.sample.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,16 @@
16871687
*/
16881688
'memcache.distributed' => '\\OC\\Memcache\\Memcached',
16891689

1690+
/**
1691+
* Cache Key Prefix for Redis or Memcached
1692+
*
1693+
* * Used for avoiding collisions in the cache system
1694+
* * May be used for ACL restrictions in Redis
1695+
*
1696+
* Defaults to ``''`` (empty string)
1697+
*/
1698+
'memcache_customprefix' => 'mycustomprefix',
1699+
16901700
/**
16911701
* Connection details for Redis to use for memory caching in a single server configuration.
16921702
*

lib/private/Memcache/Factory.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function __construct(
113113
protected function getGlobalPrefix(): string {
114114
if ($this->globalPrefix === null) {
115115
$config = \OCP\Server::get(SystemConfig::class);
116+
$customprefix = $config->getValue('memcache_customprefix', '');
116117
$maintenanceMode = $config->getValue('maintenance', false);
117118
$versions = [];
118119
if ($config->getValue('installed', false) && !$maintenanceMode) {
@@ -129,7 +130,7 @@ protected function getGlobalPrefix(): string {
129130
// Include instanceid in the prefix, in case multiple instances use the same cache (e.g. same FPM pool)
130131
$instanceid = $config->getValue('instanceid');
131132
$installedApps = implode(',', array_keys($versions)) . implode(',', array_values($versions));
132-
$this->globalPrefix = hash('xxh128', $instanceid . $installedApps);
133+
$this->globalPrefix = $customprefix . hash('xxh128', $instanceid . $installedApps);
133134
}
134135
return $this->globalPrefix;
135136
}
@@ -143,9 +144,11 @@ protected function getGlobalPrefix(): string {
143144
public function withServerVersionPrefix(\Closure $closure): void {
144145
$backupPrefix = $this->globalPrefix;
145146

147+
$config = \OCP\Server::get(SystemConfig::class);
148+
$customprefix = $config->getValue('memcache_customprefix', '');
146149
// Include instanceid in the prefix, in case multiple instances use the same cache (e.g. same FPM pool)
147-
$instanceid = \OCP\Server::get(SystemConfig::class)->getValue('instanceid');
148-
$this->globalPrefix = hash('xxh128', $instanceid . implode('.', $this->serverVersion->getVersion()));
150+
$instanceid = $config->getValue('instanceid');
151+
$this->globalPrefix = $customprefix . hash('xxh128', $instanceid . implode('.', $this->serverVersion->getVersion()));
149152
$closure($this);
150153
$this->globalPrefix = $backupPrefix;
151154
}

0 commit comments

Comments
 (0)