Skip to content

feat(cache): Add ability for optional custom prefix for Redis/Memcached cache keys#58334

Open
Earl0fPudding wants to merge 3 commits intonextcloud:masterfrom
Earl0fPudding:custom-cache-prefix
Open

feat(cache): Add ability for optional custom prefix for Redis/Memcached cache keys#58334
Earl0fPudding wants to merge 3 commits intonextcloud:masterfrom
Earl0fPudding:custom-cache-prefix

Conversation

@Earl0fPudding
Copy link

@Earl0fPudding Earl0fPudding commented Feb 13, 2026

Summary

This adds the ability to use a custom prefix for Redis and Memcached keys. This is an optional variable.

One can use the variable setting memcache.customprefix for this.

Checklist

Signed-off-by: Martin <31348196+Earl0fPudding@users.noreply.github.com>
@Earl0fPudding Earl0fPudding requested a review from a team as a code owner February 13, 2026 15:30
@Earl0fPudding Earl0fPudding requested review from Altahrim, ArtificialOwl, come-nc and icewind1991 and removed request for a team February 13, 2026 15:30
@Earl0fPudding Earl0fPudding changed the title Add ability for optional custom prefix for Redis/Memcached cache keys feat(cache): Add ability for optional custom prefix for Redis/Memcached cache keys Feb 13, 2026
@Earl0fPudding
Copy link
Author

Backport to v32 would be perfect.

@kesselb
Copy link
Contributor

kesselb commented Feb 16, 2026

Thanks for your pr 👍

This should be implemented in https://github.com/nextcloud/server/blob/master/lib/private/Memcache/Factory.php

Signed-off-by: Martin <31348196+Earl0fPudding@users.noreply.github.com>
Signed-off-by: Martin <31348196+Earl0fPudding@users.noreply.github.com>
@Earl0fPudding
Copy link
Author

Thank you for your feedback, @kesselb !
I've implemented it this way now.

@Earl0fPudding
Copy link
Author

PR for documentation: nextcloud/documentation#14080

@Earl0fPudding
Copy link
Author

/backport to stable32

} else {
// if not installed or in maintenance mode, we should distinguish between both states.
$versions['core:maintenance'] = $maintenanceMode ? '1' : '0';
$customprefix = $config->getValue('memcache.customprefix', '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$customprefix = $config->getValue('memcache.customprefix', '');
$customprefix = $config->getValue('memcache_customprefix', '');

New configuration options should follow https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/configuration.html#naming-conventions. It's okay, that they don't align with the other memache. keys.

$versions['core:maintenance'] = $maintenanceMode ? '1' : '0';
$customprefix = $config->getValue('memcache.customprefix', '');
// use the value of memcache.customprefix setting as prefix if set
if ($customprefix != '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a bad idea 🙈

Using the maintenance mode yes/no, server version and app version as global prefix ensures, that installing apps, updating nextcloud, etc automatically invalidates the old (after updating sometimes even invalid or unexpected) cache.

Remove the else block and prepend the custom prefix before the hash when assigning to globalPrefix.

$config = Server::get(SystemConfig::class);
$customprefix = $config->getValue('memcache.customprefix', '');
// use the value of memcache.customprefix setting as prefix if set
if ($customprefix != '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ;)

Bonus points if you adjust $instanceid to use $config and not fetch SYstemConfig a second time from the container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for (optional) Redis Key Prefix

2 participants