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

Using a Django Request Cache in place of Memoized Cache. #12

Open
robrap opened this issue May 11, 2018 · 2 comments
Open

Using a Django Request Cache in place of Memoized Cache. #12

robrap opened this issue May 11, 2018 · 2 comments

Comments

@robrap
Copy link

robrap commented May 11, 2018

Hello.

I was implementing my own version of a TieredCache in Django when a colleague pointed me to this caching solution. I like it, but the local cache I want is a Request Cache, rather than the Timed Memoized Cache. I also heard you may already have a Request Cache version available?

Thank you.

Robert

@dannyroberts
Copy link
Member

There are currently two ways that you achieve the effect of request-scoping all in-memory caching:

  • Option 1: Pass in a session_function which takes no arguments and returns a short string that varies on request or threading.local() or whatever else you use to define a "session" or single conceptual execution period. For an example of how we've done that in another project, you can refer to: https://github.com/dimagi/commcare-hq/blob/08dde6f16afaf3aed1d1ee500986e3b06aab6bc3/corehq/util/quickcache.py#L19-L47
  • Option 2: Write a Django cache backend that stores the cache on the request or threading.local(). If you name this cache 'locmem' in your settings.py, quickcache will use it.

It occurs to me that I have not documented that get_django_quickcache uses your Django caches named 'default' (for shared cache) and 'locmem' (for in-memory cache), and that these should be something you can specify when calling get_django_quickcache. I've opened an issue about this #13

@robrap
Copy link
Author

robrap commented May 11, 2018

Thanks for your response Danny. I'll let you know if I have any questions, but hopefully this should cover it.

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