mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
Attach updated endpoint signature to inner
Not all endpoints accept a __signature__ attribute, nor should the cache decorator modify the decorated endpoint. Attach the signature to the returned inner function instead. While here, refactor the signature updating code, and extract it to a separate function.
This commit is contained in:
@@ -67,6 +67,19 @@ async def cache_response_obj():
|
||||
return JSONResponse({"a": 1})
|
||||
|
||||
|
||||
class SomeClass:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
async def handler_method(self):
|
||||
return self.value
|
||||
|
||||
|
||||
# register an instance method as a handler
|
||||
instance = SomeClass(17)
|
||||
app.get("/method")(cache(namespace="test")(instance.handler_method))
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
FastAPICache.init(InMemoryBackend())
|
||||
|
||||
Reference in New Issue
Block a user