Skip to content

Instantly share code, notes, and snippets.

@redrush85
Last active December 28, 2016 16:51
Show Gist options
  • Save redrush85/3d3d637c39879f8be97a96233d244f92 to your computer and use it in GitHub Desktop.
Save redrush85/3d3d637c39879f8be97a96233d244f92 to your computer and use it in GitHub Desktop.
def async_cached(cache, key=hashkey):
def decorator(fn):
async def wrapper(*args, **kwargs):
k = key(*args, **kwargs)
if k not in cache:
result = await fn(*args, **kwargs)
if result is None:
return result
cache[k] = result
return cache[k]
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment