a-luna / fastapi-redis-cache

A simple and robust caching solution for FastAPI that interprets request header values and creates proper response header values (powered by Redis)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use cache() decorator outside of fastapi

cmabastar opened this issue · 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 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

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: #66