fastapi-redis-cache icon indicating copy to clipboard operation
fastapi-redis-cache copied to clipboard

Use cache() decorator outside of fastapi

Open cmabastar opened this issue 2 years ago • 3 comments

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 avatar Sep 24 '21 14:09 cmabastar

@cmabastar here are two links which don't use this package but set cache using the background task feature of fastapi.

  1. https://developer.redis.com/develop/python/fastapi/
  2. https://github.com/redis-developer/fastapi-redis-tutorial/blob/master/app/main.py

kishvanchee avatar May 03 '22 11:05 kishvanchee

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

bkanuka avatar Jun 02 '22 16:06 bkanuka

I've opened a pull request for this: https://github.com/a-luna/fastapi-redis-cache/pull/66

bkanuka avatar Jun 02 '22 21:06 bkanuka