Skip to content

Commit 2a2f42e

Browse files
Earl0fPuddingkesselb
authored andcommitted
feat: Add memcache_customprefix
Signed-off-by: Martin <31348196+Earl0fPudding@users.noreply.github.com>
1 parent 35ef9b0 commit 2a2f42e

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
@@ -1758,6 +1758,16 @@
17581758
*/
17591759
'memcache.distributed' => '\\OC\\Memcache\\Memcached',
17601760

1761+
/**
1762+
* Cache Key Prefix for Redis or Memcached
1763+
*
1764+
* * Used for avoiding collisions in the cache system
1765+
* * May be used for ACL restrictions in Redis
1766+
*
1767+
* Defaults to ``''`` (empty string)
1768+
*/
1769+
'memcache_customprefix' => 'mycustomprefix',
1770+
17611771
/**
17621772
* Connection details for Redis to use for memory caching in a single server configuration.
17631773
*

lib/private/Memcache/Factory.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function __construct(
115115
protected function getGlobalPrefix(): string {
116116
if ($this->globalPrefix === null) {
117117
$config = Server::get(SystemConfig::class);
118+
$customprefix = $config->getValue('memcache_customprefix', '');
118119
$maintenanceMode = $config->getValue('maintenance', false);
119120
$versions = [];
120121
if ($config->getValue('installed', false) && !$maintenanceMode) {
@@ -131,7 +132,7 @@ protected function getGlobalPrefix(): string {
131132
// Include instanceid in the prefix, in case multiple instances use the same cache (e.g. same FPM pool)
132133
$instanceid = $config->getValue('instanceid');
133134
$installedApps = implode(',', array_keys($versions)) . implode(',', array_values($versions));
134-
$this->globalPrefix = hash('xxh128', $instanceid . $installedApps);
135+
$this->globalPrefix = $customprefix . hash('xxh128', $instanceid . $installedApps);
135136
}
136137
return $this->globalPrefix;
137138
}
@@ -145,9 +146,11 @@ protected function getGlobalPrefix(): string {
145146
public function withServerVersionPrefix(\Closure $closure): void {
146147
$backupPrefix = $this->globalPrefix;
147148

149+
$config = Server::get(SystemConfig::class);
150+
$customprefix = $config->getValue('memcache_customprefix', '');
148151
// Include instanceid in the prefix, in case multiple instances use the same cache (e.g. same FPM pool)
149-
$instanceid = Server::get(SystemConfig::class)->getValue('instanceid');
150-
$this->globalPrefix = hash('xxh128', $instanceid . implode('.', $this->serverVersion->getVersion()));
152+
$instanceid = $config->getValue('instanceid');
153+
$this->globalPrefix = $customprefix . hash('xxh128', $instanceid . implode('.', $this->serverVersion->getVersion()));
151154
$closure($this);
152155
$this->globalPrefix = $backupPrefix;
153156
}

0 commit comments

Comments
 (0)