Hi,

I am not en expert but since I had a similar problem I found a solution.
I just attached data I wanted to persist to the request.  You can put the
common code in a middleware to be computed early and then use it in your
views.  You can also add it to the session data (i.e. request.session)
and after you process the view delete it.  But then the session will be
marked as both accessed and modified, and even though at the end you
haven't change the data (since you deleted what you have added) it will
be written to the database (or a file depending which session backend
you use).

Best regards,
Marcin


On 09:58 Mon 10 Jun     , Kurtis wrote:
> I have two views which perform a ton of DB queries. The views themselves 
> don't perform the queries; they simply call quite a few Model methods to 
> build the context data. I understand that I could simply build one method 
> to re-use the data but I'd like to sustain the "Object Oriented" quality of 
> the code I've developed.
> 
> If possible, I'd like to be able to cache these queries when these views 
> are called. A lot of the queries are simply re-produced but perform 
> different calculations or what-not based on the method called.
> 
> These views do not create persistent data; they simply hit the database and 
> return calculated results from what's in there.
> 
> The caching mechanism should simply persist through the duration of the 
> request. For example, subsequent requests should not use cached results 
> from a previous request.
> 
> Let me know if anybody has suggestions or experience with implementing 
> something along these lines. I have some 'creative' ideas on how to do it 
> but I'd like to get some input first.
> 
> Thanks!
> - Kurtis
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to