Re: trying to get a cache per request

2010-10-10 Thread Miguel Araujo
Thanks again Doug, I understand your method. I think the problem is that it might be too much overhead for what I can gain using a cache, so I might drop the idea of adding one. In any case, your explanation will be probably worth in future projects :) Regards, Miguel 2010/10/10 Doug > Look ar

Re: trying to get a cache per request

2010-10-09 Thread Doug
Look around for python docs on threading.local, which lets you set a 'global' variable for just that thread. Since a request is only going to happen in a single thread, that lets you have a per-request global that can be used for cache storage. With middleware to set the threading local instance

Re: trying to get a cache per request

2010-10-09 Thread Miguel Araujo
Thanks Doug, In my Django-app where I want to create a cache, I don't have a request parameter and I can not add it because I need to be compatible with a part of the framework itself. I don't need to access that cache in the templates anywhere. I would like that my objects persists only per requ

Re: trying to get a cache per request

2010-10-09 Thread Doug
Why not just stick it on the request object? def myview(request): request.mycache=MyCacheClass() then it's available everywhere the request object is. If you are wanting something that can be used in a template tag without explicitly passing the request object (or your cache object) in, you

trying to get a cache per request

2010-10-09 Thread maraujop
Hi there, I'm working on a Django-app that will benefit from having a per request cache, which means that the cache should reset every time there is a new request or it finishes a response. I don't want to use a middleware approach for this, I would like to create an object that lived within the r