diff --git a/README.md b/README.md index 4bac1398..e9c4cefb 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ async def index(): By default the `default_key_builder` builtin key builder is used; this creates a cache key from the function module and name, and the positional and keyword -arguments converted to their `repr()` representations, encoded as a MD5 hash. +arguments converted to their `repr()` representations, encoded as a BLAKE2 hash. You can provide your own by passing a key builder in to `@cache()`, or to `FastAPICache.init()` to apply globally. diff --git a/changelog.d/264.feature.md b/changelog.d/264.feature.md new file mode 100644 index 00000000..8c6da519 --- /dev/null +++ b/changelog.d/264.feature.md @@ -0,0 +1 @@ +Use BLAKE2 instead of MD5. \ No newline at end of file diff --git a/fastapi_cache/key_builder.py b/fastapi_cache/key_builder.py index feee3a63..9d60a555 100644 --- a/fastapi_cache/key_builder.py +++ b/fastapi_cache/key_builder.py @@ -14,7 +14,7 @@ def default_key_builder( args: Tuple[Any, ...], kwargs: Dict[str, Any], ) -> str: - cache_key = hashlib.md5( # noqa: S324 + cache_key = hashlib.blake2b( f"{func.__module__}:{func.__name__}:{args}:{kwargs}".encode() ).hexdigest() return f"{namespace}:{cache_key}"