Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrongly sharing the cache between different sites #6572

Open
JensKirk opened this issue Nov 13, 2019 · 3 comments
Open

Wrongly sharing the cache between different sites #6572

JensKirk opened this issue Nov 13, 2019 · 3 comments

Comments

@JensKirk
Copy link

Hi :-)

We are a client at FastComet with a dedicated server. FastComet Support is helping us installing your Redis Cache server but it is wrongly sharing the cache between the different sites that have enabled Redis cache. This is making all kinds of random errors.

We are using this WP plugin: https://da.wordpress.org/plugins/redis-cache/

We have disabled it for now and have flushed the cache via the terminal (WHM) so the sites are working again.

Can you tell us how to set up the Redis at the server level so it does not share cache between different sites?

@mgravell
Copy link

mgravell commented Nov 13, 2019

There are three common ways of partitioning data for his kind of scenario:

  1. use different database numbers per site

Redis (not including "cluster") supports the notion of multiple numbered databases that are independent key-spaces. Somewhere in your code or config you'd associate a database number per site, and away you go.

  1. use a key prefix per site

Since redis keys are essentially strings, it is usually possible to simply prefix each key with some token, perhaps a numeric I'd of the site, or perhaps the base host address, so instead of "/foo/bar" you use a key of "whatever.com/foo/bar". Since "cluster" doesn't support database numbers, key prefix may be preferable if you are now, or in the future, considering using "cluster".

  1. use a redis node (TCP port) per site

Redis instances are relatively cheap to spin up, so in some scenarios it makes sense to just have a separate redis process per site. This takes more configuration, but provides the highest isolation.

The first two may or may not be trivially configurable in whatever client library or middleware you're using for the caching. But that's really a question for whatever client library or middleware you're using!

@JensKirk
Copy link
Author

JensKirk commented Nov 13, 2019 via email

@mgravell
Copy link

mgravell commented Nov 13, 2019

Reading on WP_CACHE_KEY_SALT, yes that looks to be for exactly this scenario, as a key-prefix; citation: https://wordpress.org/support/topic/clarification-on-when-to-use-wp_cache_key_salt/ or https://easyengine.io/tutorials/wordpress/redis-wordpress-object-cache/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants