Suor / django-cacheops

A slick ORM cache with automatic granular event-driven invalidation.
BSD 3-Clause "New" or "Revised" License
2.1k stars 227 forks source link

Adds prefix to all keys. Adds ignore_prefix kwarg. #396

Closed scuml closed 3 years ago

scuml commented 3 years ago

Resolves #325

Adds the prefix to all decorators, and simple caching methods. As this plugs a giant potential security issue where cache can leak between different deployments and applications, namespacing all keys is critical and should be the default behavior. I've included the ability to revert to the previous key names by adding the parameter ignore_prefix to the decorators and simple cache methods. This allows cache to be shared by eliminating the prefix, but only if the user explicitly requests it.

Suor commented 3 years ago

Thanks for your interest @scuml.

If you want to add prefix to simple cache then you should do it at BaseCache level. You will probably need to provide .get(), .set() and .delete() there calling backend specific ._get() and friends from its descendants, this will ensure you won't have discrepancy between them.

On implementation - let's not add ignore_prefix so far. Switching back on function by function basis doesn't really look practical anyway. We may think about how it can be exposed on PrefixQuery though, so that people will be able to opt out on config level. Don't need to go into this PR.

Also please avoid whitespace only changes, i.e. new empty newlines.

Suor commented 3 years ago

Closing in favor of https://github.com/Suor/django-cacheops/commit/e29dcbc8fbf1845e9249bd5a4a8462fa846afb80.