Files
fastapi-cache/fastapi_cache/key_builder.py
Martijn Pieters 50e3f91a87 Add flake8-bandit linting (#156)
The linter has been used in the past, so most assertions for these were
already there but needed to be updated to use `noqa: S` instead of
`nosec: B` annotations.
2023-05-16 12:11:10 +00:00

21 lines
555 B
Python

import hashlib
from typing import Any, Callable, Dict, Optional, Tuple
from starlette.requests import Request
from starlette.responses import Response
def default_key_builder(
func: Callable[..., Any],
namespace: str = "",
*,
request: Optional[Request] = None,
response: Optional[Response] = None,
args: Tuple[Any, ...],
kwargs: Dict[str, Any],
) -> str:
cache_key = hashlib.md5( # noqa: S324
f"{func.__module__}:{func.__name__}:{args}:{kwargs}".encode()
).hexdigest()
return f"{namespace}:{cache_key}"