Spaces:
Running
Running
Download app/core/cache.py from yCamelow/docboard-api: direct link, hf CLI and curl.
- Browser
- Download file 809 Bytes
-
https://huggingface.co/spaces/yCamelow/docboard-api/resolve/main/app/core/cache.py
- Command line
-
hf download hf://spaces/yCamelow/docboard-api/app/core/cache.py
-
curl -L -o cache.py https://huggingface.co/spaces/yCamelow/docboard-api/resolve/main/app/core/cache.py
809 Bytes
| from fastapi import Request, Response | |
| from fastapi_cache import FastAPICache | |
| def user_key_builder( | |
| func, | |
| namespace: str = "", | |
| request: Request = None, | |
| response: Response = None, | |
| *args, | |
| **kwargs, | |
| ): | |
| """ | |
| Custom key builder that includes the current user's ID in the cache key. | |
| This prevents caching data leaks across different teams/users. | |
| """ | |
| # Pega o usuário logado que foi injetado pela rota (no caso, via current_user) | |
| user = kwargs.get("current_user") | |
| user_id = user.id if user else "anonymous" | |
| # Cria uma chave única baseada no prefixo, namespace, nome da função, ID do usuário e parâmetros da URL | |
| return f"{FastAPICache.get_prefix()}:{namespace}:{func.__module__}:{func.__name__}:{user_id}:{request.url.query}" | |