def wrapper(*args, **kwargs): key = self._make_cache_key(fn, args, kwargs) value = memcached.get(key) if value: value = MemorizedObject(value) value.from_cache = True else: value = fn(*args, **kwargs) memcached.set(key, value, time=self.ttl) value = MemorizedObject(value) value.cache_key = key return value
def wrapper(*args, **kwargs): key = self._make_cache_key(fn, args, kwargs) value = memcached.get(key) if value: value = MemorizedObject(value) value.from_cache = True else: # TODO: kick off a task here, instead of calculating the value. # https://github.com/mozilla/universal-search-recommendation/issues/11 value = fn(*args, **kwargs) memcached.set(key, value, time=self.ttl) if self.error_on_miss: raise CacheMissError() value = MemorizedObject(value) value.cache_key = key return value
def recommend(q, key): recommendation = SearchRecommendation(q).do_search(q) memcached.set(key, recommendation) return recommendation