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

Cache doesnt doesnt "discriminate" between args

Open TC-CPHI opened this issue 11 months ago • 1 comments

Hello,

Im trying to implement an in memory cache which looks at the following function. The goal is to have a cache for the same types of fromdate and todate queries that are called with the function. Yet when implementing an in memory cache as follows it always returns the same query results despite the args of the function changing to new fromdate and todate's. I've tried with custom key builders and various approaches but it seems that the cache itself is flawed?

@asynccontextmanager
async def lifespan(app: FastAPI):
    FastAPICache.init(InMemoryBackend())
    yield

app = FastAPI(lifespan=lifespan)


@app.get("/InitInt")
@cache(expire=3600)
async def InitializeInternal(api_key_fetch: str = Depends(header_scheme), fromdate : Annotated[str, Header()] = None, todate : Annotated[str, Header()] = None, offset : Annotated[int, Header()] = None):

#SOME SQL CODE

TC-CPHI avatar Nov 11 '24 08:11 TC-CPHI