예제 #1
0
 def _func(keys, **kwargs):
     if not keys:
         return {}
     keys = list(keys)
     force_query = kwargs.get("force_query", False)
     result_data = {}
     if not force_query:
         cache_key_map = {cache_prefix % key: key for key in keys}
         cached_data_dict = cache.get_cache(cache_name).get_many(
             cache_key_map.keys())
         for cached_key, cached_data in cached_data_dict.iteritems():
             key = cache_key_map[cached_key]
             result_data[key] = cached_data
             keys.remove(key)
         log.info("key_cache_hit|cached_key=%s",
                  ','.join(cached_data_dict.keys()))
     if keys:
         response_data = func(keys)
         if response_data:
             data_to_cache = {
                 cache_prefix % key: data
                 for key, data in response_data.iteritems()
             }
             cache.get_cache(cache_name).set_many(
                 data_to_cache, expiry_time)
         return dict(result_data.items() + response_data.items())
     else:
         return result_data
예제 #2
0
def cache_set_json(key,
                   dict_value,
                   expiry_time=DEFAULT_EXPIRE,
                   client_id="default"):
    # No cache on TEST
    if not config.TEST:
        cache.get_cache(client_id).set(key, jsonutils.to_json(dict_value),
                                       expiry_time)
예제 #3
0
 def _func(*args, **kwargs):
     cache_key = cache_key_converter(cache_prefix, *args)
     data = cache.get_cache(cache_name).get(cache_key)
     force_query = kwargs.get("force_query", False)
     if force_query or data is None:
         data = func(*args)
         cache.get_cache(cache_name).set(cache_key, data, expiry_time)
     else:
         log.info("cache_hit|cache_key=%s", cache_key)
     return data
예제 #4
0
def _build_ha_service(conf):
    logging.debug('creating `HA` weather service')
    fast_cache = cache.get_cache(storage=conf['fast_cache_type'], **conf)
    slow_cache = cache.get_cache(storage=conf['slow_cache_type'], **conf)

    return HAService(conf, get_parser(conf),
                     fast_cache, slow_cache,
                     get_tools(conf),
                     get_sender(conf),
                     get_api(conf))
예제 #5
0
def get_practice_last_action(trainer_address, client_id="default"):
    return cache.get_cache(client_id).get(CACHE_PRACTICE_LAST_ACTION %
                                          trainer_address)
예제 #6
0
def cache_delete_json(key, client_id="default"):
    cache.get_cache(client_id).delete(key)
예제 #7
0
def cache_get_json(key, client_id="default"):
    # No cache on TEST
    if not config.TEST:
        return jsonutils.from_json_safe(cache.get_cache(client_id).get(key))
    else:
        return None
예제 #8
0
def set_practice_last_action(trainer_address,
                             value,
                             expiry_time=0,
                             client_id="default"):
    cache.get_cache(client_id).set(
        CACHE_PRACTICE_LAST_ACTION % trainer_address, value, expiry_time)