Skip to content

Commit 8afb769

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

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

config/config.sample.php

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,32 +1687,42 @@
16871687
*/
16881688
'memcache.distributed' => '\\OC\\Memcache\\Memcached',
16891689

1690-
/**
1691-
* Connection details for Redis to use for memory caching in a single server configuration.
1692-
*
1693-
* For enhanced security, it is recommended to configure Redis
1694-
* to require a password. See http://redis.io/topics/security
1695-
* for more information.
1696-
*
1697-
* We also support Redis SSL/TLS encryption as of version 6.
1698-
* See https://redis.io/topics/encryption for more information.
1699-
*/
1700-
'redis' => [
1701-
'host' => 'localhost', // can also be a Unix domain socket: '/tmp/redis.sock'
1702-
'port' => 6379,
1703-
'timeout' => 0.0,
1704-
'read_timeout' => 0.0,
1705-
'user' => '', // Optional: if not defined, no password will be used.
1706-
'password' => '', // Optional: if not defined, no password will be used.
1707-
'dbindex' => 0, // Optional: if undefined, SELECT will not run and will use Redis Server's default DB Index.
1708-
// If Redis in-transit encryption is enabled, provide certificates
1709-
// SSL context https://www.php.net/manual/en/context.ssl.php
1710-
'ssl_context' => [
1711-
'local_cert' => '/certs/redis.crt',
1712-
'local_pk' => '/certs/redis.key',
1713-
'cafile' => '/certs/ca.crt'
1714-
]
1715-
],
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+
1700+
/**
1701+
* Connection details for Redis to use for memory caching in a single server configuration.
1702+
*
1703+
* For enhanced security, it is recommended to configure Redis
1704+
* to require a password. See http://redis.io/topics/security
1705+
* for more information.
1706+
*
1707+
* We also support Redis SSL/TLS encryption as of version 6.
1708+
* See https://redis.io/topics/encryption for more information.
1709+
*/
1710+
'redis' => [
1711+
'host' => 'localhost', // can also be a Unix domain socket: '/tmp/redis.sock'
1712+
'port' => 6379,
1713+
'timeout' => 0.0,
1714+
'read_timeout' => 0.0,
1715+
'user' => '', // Optional: if not defined, no password will be used.
1716+
'password' => '', // Optional: if not defined, no password will be used.
1717+
'dbindex' => 0, // Optional: if undefined, SELECT will not run and will use Redis Server's default DB Index.
1718+
// If Redis in-transit encryption is enabled, provide certificates
1719+
// SSL context https://www.php.net/manual/en/context.ssl.php
1720+
'ssl_context' => [
1721+
'local_cert' => '/certs/redis.crt',
1722+
'local_pk' => '/certs/redis.key',
1723+
'cafile' => '/certs/ca.crt'
1724+
]
1725+
],
17161726

17171727
/**
17181728
* Connection details for a Redis Cluster.

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)