Skip to content

Make it possible to specify current cache more easily #147

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

Open
djackson-exo-inc opened this issue May 1, 2023 · 0 comments
Open

Make it possible to specify current cache more easily #147

djackson-exo-inc opened this issue May 1, 2023 · 0 comments

Comments

@djackson-exo-inc
Copy link

djackson-exo-inc commented May 1, 2023

I have a use case where I need to dynamically change my cache to point to a different Redis endpoint depending on how my Django code is executed. My Django code sits in a lambda, and can end up being applied to different environments, which use different caching endpoints.

Unfortunately, the way this package is implemented, the "cache" variable (current cache to use) is a global variable at the module scope of the invalidation.py module and cannot be easily overridden. I thought about subclassing, but that's no good unless I create my own version of everything in the invalidation.py module and then subclass everything that imports it.

from caching import config

try:
    import redis as redislib
except ImportError:
    redislib = None

# Look for an own cache first before falling back to the default cache
try:
    cache = caches["cache_machine"]
except (InvalidCacheBackendError, ValueError):
    cache = default_cache

log = logging.getLogger("caching.invalidation")

It seems like it would be a simple change on your end to create a class with some class-vars and class methods for setting/getting the current cache and have all the other classes reference that. Then, before I start instantiating the other classes, I could just set the current cache in that one class, and everything would pick it up.

My only option at this point is to copy this entire package into my codebase and modify it as I suggested or to fork it with the proposed changes. I'd rather give you all the chance to make the change, rather than end up with lots of forks lying around (although looks like you already have 162 of them...)

If you can respond quickly just to indicate if this is something you'd be willing to consider, or if you're willing to let me make the change (I'm happy to), and then create a PR for your review, that would be super helpful as I need this functionality pretty soon.

Thanks!

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

1 participant