Wiadomość napisana w dniu 2009-05-21, o godz. 10:16, przez mark hellewell:
> I've written a few decorators for my views. Each of the decorators > operate on the same object obtained from the db backend using ORM > and each checks different things. I'll chain them together > sometimes, but not always. In the decorated view I'll usually be > doing yet another MyObjectClass.objects.get(...) (as I've done in > each of the decorators already) to carry out some operation or other > on the object. > > My question is, is there some way to either avoid having to make > repeated ORM queries in each of the decorators or to cache the > result of the first ORM query (no matter which decorator it's > obtained from)? All I'm usually doing it a .get(id=123) to get an > object to work on and it feels wasteful. > > Is some form of middleware to cache db queries the "done thing" > here? Not sure where to start. Use low-level Django cache framework to cache retrieved object but don't forget to invalidate the cache upon each change to this object. Like: obj = cache.get(obj_key) if not obj: obj = ObjClass.objects.get(pk=obj_pk) cache.set(obj_key, obj) return obj -- Artificial intelligence stands no chance against natural stupidity Jarek Zgoda, R&D, Redefine jarek.zg...@redefine.pl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---