# LRU CachefromcacheimportAsyncLRU@AsyncLRU(maxsize=128)asyncdeffunc(*args, **kwargs):
""" maxsize : max number of results that are cached. if max limit is reached the oldest result is deleted. """pass# TTL CachefromcacheimportAsyncTTL@AsyncTTL(time_to_live=60, maxsize=1024)asyncdeffunc(*args, **kwargs):
""" time_to_live : max time for which a cached result is valid maxsize : max number of results that are cached. if max limit is reached the oldest result is deleted. """pass# Supports primitive as well as non-primitive function parameter.# Currently TTL & LRU cache is supported.
Advanced Usage
classCustomDataClass:
id: intvalue: intfromcacheimportAsyncLRU@AsyncLRU(maxsize=128)asyncdeffunc(model: "CustomDataClass"):
...
# function logic
...
# async-cache will work even if function parameters are:# 1. orm objects# 2. request object# 3. any other custom object type.