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 set(self, value, *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']

        timeout = None

        if 'timeout' in kwargs:
            timeout = kwargs.pop('timeout')

        key = self.build_key(*generations, **kwargs)
        raw_cache.set(key, value, timeout=timeout)

        if in_gen_cache_debug_mode():
            logging.debug("gen_cache.set: %s to %s" % (key, value))
Example #3
0
def test_cache():
    now = time()
    key = 'unittestnowtimeisrawcache:%s' % now
    cache.set(key, now)
    
    val = cache.get(key)