feat(api): add cache + busting for admin
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from ninja import NinjaAPI
|
||||
from django.core.cache import cache
|
||||
from django.http import HttpRequest
|
||||
from submissions.api import router as submissions_router
|
||||
from submissions.schemas import UserInfoOut
|
||||
from animations.api import router as results_router
|
||||
@@ -41,6 +43,19 @@ def health_check(request):
|
||||
return {"status": "healthy", "service": "polylan-submitter-api"}
|
||||
|
||||
|
||||
# Cache management endpoint
|
||||
@api.post("/cache/clear")
|
||||
def clear_cache(request: HttpRequest):
|
||||
"""Clear all API caches (admin only)"""
|
||||
if not request.user.is_authenticated or not request.user.is_staff:
|
||||
return 403, {"detail": "Admin access required"}
|
||||
|
||||
keys = cache.keys("api:*")
|
||||
cache.delete_many(keys)
|
||||
|
||||
return {"detail": f"Cleared {len(keys)} cache entries"}
|
||||
|
||||
|
||||
# User info endpoint
|
||||
@api.get("/user", response=UserInfoOut)
|
||||
def get_user_info(request):
|
||||
|
||||
@@ -145,6 +145,18 @@ MEDIA_ROOT = BASE_DIR / "media"
|
||||
FILE_UPLOAD_MAX_MEMORY_SIZE = 256 * 1024 * 1024 # 256MB
|
||||
DATA_UPLOAD_MAX_MEMORY_SIZE = 256 * 1024 * 1024 # 256MB
|
||||
|
||||
# Caching Configuration
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/11",
|
||||
"TIMEOUT": 300, # 5 minutes default
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
# Allowed file types for submissions
|
||||
ALLOWED_SUBMISSION_TYPES = [
|
||||
"image/jpeg",
|
||||
|
||||
Reference in New Issue
Block a user