On 7/10/06, Ian Holsman <[EMAIL PROTECTED]> wrote:
> class SmallQuerySet(QuerySet):
>      cache={}
>      def get(self, *args, **kwargs):
>          cachekey = "%s:%s:%s" % (self.model,  str(args), str(kwargs ) )
>          if self.cache.has_key( cachekey ) :
>              return self.cache[cachekey]
>          x= super(SmallQuerySet, self).get(*args,**kwargs)
>          self.cache[ cachekey ] = x
>          return x

A coupla suggestions for ya:

* Try using the real Django cache framework rather than a dictionary
-- all it takes is a "from django.core.cache import cache", and the
advantage there is that you can choose from different cache backends.

* Your calculation of the cache key is imperfect, because it relies on
str(kwargs) always returning the same thing. It's generally not a good
idea to rely on the str(), repr() or order of a dictionary, because
its keys/values are to be treated as unordered. Maybe you could use a
"normalized" version of the dictionary -- perhaps sort it before
taking str().

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to