mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
fix: request and response type hints
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import inspect
|
||||
import sys
|
||||
from functools import wraps
|
||||
from typing import Any, Awaitable, Callable, Optional, TypeVar
|
||||
from typing import Any, Awaitable, Callable, Optional, TypeVar, Type
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from typing import ParamSpec
|
||||
else:
|
||||
@@ -21,7 +22,7 @@ R = TypeVar("R")
|
||||
|
||||
def cache(
|
||||
expire: Optional[int] = None,
|
||||
coder: Optional[Coder] = None,
|
||||
coder: Optional[Type[Coder]] = None,
|
||||
key_builder: Optional[Callable[..., Any]] = None,
|
||||
namespace: Optional[str] = "",
|
||||
) -> Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[R]]]:
|
||||
@@ -92,10 +93,9 @@ def cache(
|
||||
# see above why we have to await even although caller also awaits.
|
||||
return await run_in_threadpool(func, *args, **kwargs)
|
||||
|
||||
|
||||
copy_kwargs = kwargs.copy()
|
||||
request = copy_kwargs.pop("request", None)
|
||||
response = copy_kwargs.pop("response", None)
|
||||
request: Optional[Request] = copy_kwargs.pop("request", None)
|
||||
response: Optional[Response] = copy_kwargs.pop("response", None)
|
||||
if (
|
||||
request and request.headers.get("Cache-Control") == "no-store"
|
||||
) or not FastAPICache.get_enable():
|
||||
|
||||
Reference in New Issue
Block a user