Vaibhav Jain
Vaibhav Jain

Reputation: 5507

django cache query result for templates and views

I want to cache a query result on per request basis. Because I need that query in multiple places. And I want to cache that query on request and use it whenever and wherever I want. And at the end of the request-response cycle it should expire . Here I found a solution but there is a discussion stating it would be dangerous

Can someone please tell me how to achieve this.

Upvotes: 0

Views: 234

Answers (1)

bvanvugt
bvanvugt

Reputation: 1242

You could modify the solution proposed here to use per-request locmemcache instances, instead of a global cache per thread.

You could then use the middleware's process_response function to then cleanup the local cache.

Upvotes: 1

Related Questions