def wrapper(*args, **kwargs): key = func_helper.build_wrapped_cache_key_with_generations(args, kwargs) value = raw_cache.get(key) # in case of cache miss recalculate the value and put it to the cache if value is None: value = func(*args, **kwargs) raw_cache.set(key, value, timeout) if log_misses is True or in_gen_cache_debug_mode(): logging.debug("Cache miss for gen_cache.wrap: %s \n key = %s" % (generations, func_helper.full_key or key)) return value
def get(self, *generations, **kwargs): # If use raw, we will avoid the default django behavior of adding a prefix and version number # to the cache key, useful for a key between apps use_raw = kwargs.get('use_raw') if use_raw != None: del kwargs['use_raw'] # TODO, docs! (don't forget the add_to_key param) if not self.should_ignore_caching(kwargs): key = self.build_key(*generations, **kwargs) result = raw_cache.get(key) if in_gen_cache_debug_mode(): logging.debug("gen_cache.get: %s => %s" % (key, result)) return result
def test_cache(): now = time() key = 'unittestnowtimeisrawcache:%s' % now cache.set(key, now) val = cache.get(key)