async def wrapper(*args, **kwargs): cache_instance = get_cache(cache=cache, serializer=serializer, plugins=plugins, **cache_kwargs) args_dict = get_args_dict(func, args, kwargs) cache_key = key or args_dict.get( key_from_attr, (func.__module__ or 'stub') + func.__name__ + str(args) + str(kwargs)) try: if await cache_instance.exists(cache_key): return await cache_instance.get(cache_key) except Exception: logger.exception("Unexpected error with %s", cache_instance) result = await func(*args, **kwargs) if result: try: await cache_instance.set(cache_key, result, ttl=ttl) except Exception: logger.exception("Unexpected error with %s", cache_instance) return result
async def wrapper(*args, **kwargs): cache_instance = get_cache(cache=cache, serializer=serializer, plugins=plugins, **cache_kwargs) partial_result = {} args_dict = _get_args_dict(func, args, kwargs) keys = args_dict[keys_from_attr] cache_keys = [key_builder(key, args_dict) for key in keys] result = None missing_keys = "all" if len(keys) > 0: missing_keys = [] try: values = await cache_instance.multi_get(cache_keys) for key, value in zip(keys, values): if value is not None: partial_result[key] = value else: missing_keys.append(key) args_dict[keys_from_attr] = missing_keys except Exception: logger.exception("Unexpected error with %s", cache_instance) missing_keys = "all" if missing_keys: result = await func(**args_dict) if result: partial_result.update(result) try: await cache_instance.multi_set( [(key_builder(key, args_dict), value) for key, value in result.items()], ttl=ttl) except Exception: logger.exception("Unexpected error with %s", cache_instance) return partial_result
async def wrapper(*args, **kwargs): args_dict = get_args_dict(fn, args, kwargs) cache_key = key or args_dict.get( key_from_attr, (fn.__module__ or 'stub') + fn.__name__ + str(args) + str(kwargs)) try: if await cache.exists(cache_key): return await cache.get(cache_key) except Exception: logger.exception("Unexpected error with %s", cache) result = await fn(*args, **kwargs) try: await cache.set(cache_key, result, ttl=ttl) except Exception: logger.exception("Unexpected error with %s", cache) return result