Example #1
0
 def _cache_get(self, obj, passive=False):
     """retrieve object from cache, if any, and merge data"""
     key = self._cache_key(obj)
     cached_obj = self.cache.get(key, None)
     if cached_obj:
         if passive:
             return merge_objects(cached_obj, obj)
         else:
             return merge_objects(obj, cached_obj)
     return obj
Example #2
0
 def cache_add(self, obj, timeout=None, passive=False):
     """store an object in the cache for later retrieval"""
     # make sure object is the correct type
     if not isinstance(obj, self.model):
         raise TypeError("%s is not a model in this QuerySet." % obj)
     # get storage key
     key = self._cache_key(obj)
     # retrieve already cached object, if any
     cached_obj = self.cache.get(key, None)
     if cached_obj:
         # merge cached object into object
         if  passive:
             obj = merge_objects(cached_obj, obj)
         else:
             obj = merge_objects(obj, cached_obj)
     # make sure that db and cache match
     obj.save()
     # cache pickled object
     self.cache.set(key, obj, timeout)
Example #3
0
 def lookup(self, *args, **kwargs):
     args = (self.asin,) + args
     bl = self.__class__.amazon.lookup(*args, **kwargs)[0]
     merge_objects(self, bl)