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

Redis cache: Prepend Matomo version number to cache key, and enforce a TTL #14314

Open
tsteur opened this issue Apr 4, 2019 · 3 comments
Open
Labels
Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement.

Comments

@tsteur
Copy link
Member

tsteur commented Apr 4, 2019

In https://matomo.org/faq/how-to/faq_20511/ we recommend to use the Redis cache when using multiple servers to run Matomo. This can result in many issues though eg when each server has a different path to the Matomo directory.

Also when updating Matomo on the servers, in most cases some servers will run a new Matomo version while other servers will run an older version of Matomo. Yet they all access the same cache. This is problematic because caches aren't compatible between Matomo versions, and they have different files etc. Meaning while deploying code (in for us takes sometimes 30min+ to update all servers) Matomo can be broken if someone uses redis cache. To workaround this issue we could prepend the Matomo version number to all cache IDs. To still invalidate the cache entries of older Matomo versions, we need to make sure that when a cache is saved with no TTL, we need to set eg 86400 to free space after a while.

I will mention in the FAQ that redis cache can only be used if they all have the same path.

@tsteur tsteur added Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. labels Apr 4, 2019
@tsteur tsteur modified the milestone: 3.13.0 Apr 4, 2019
@ronyb29
Copy link

ronyb29 commented Oct 8, 2019

Hey, I've been looking around the code on how to implement this.
Noticed the cache implementation are on a separate package that's published separately.

Do you think it makes sense then, to implement a wrapper int his repo for all the caches and add the version number from the wrapper?

@tsteur
Copy link
Member Author

tsteur commented Oct 8, 2019

I totally get what you mean. This is not trivial. Fixing it in the package then we have the problem it might have a dependency to Matomo which we maybe don't want. Doing this in Matomo core seems not quite possible either.

I see in config/global.php that the "eager" cache has already the version number integrated. I suppose we would need to change vendor/piwik/cache/src/Backend/Factory.php to add a new option in buildRedisCache() like some cacheIdPrefix which then be passed to the Redis class and the Redis class would always prefix that cacheId. Hope that helps.

@ronyb29
Copy link

ronyb29 commented Oct 9, 2019

Sounds great. I'll look into it tonight and see if i can put the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement.
Projects
None yet
Development

No branches or pull requests

3 participants