fastapi-redis-cache
fastapi-redis-cache copied to clipboard
Use cache() decorator outside of fastapi
Hi i'm trying to use @cache() decorator using a worker like celery/dramatiq. Is there a way to use decorator outside of fastapi?
@cache()
def long_function_query(word):
pass # do long running stuff.
@cmabastar here are two links which don't use this package but set cache using the background task feature of fastapi.
- https://developer.redis.com/develop/python/fastapi/
- https://github.com/redis-developer/fastapi-redis-tutorial/blob/master/app/main.py
Also interested in this. There are some data tasks we need to do on startup of our FastAPI app, that can be/should be cached. So the functions are not specifically part of a FastAPI request function (want that too!). So being able to use cache outside a request function would allow us to cache those startup functions also
I've opened a pull request for this: https://github.com/a-luna/fastapi-redis-cache/pull/66