You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a pretty new feature - a part of contrib part for fastapi ( obvious )
cache_control_ttl works only with CacheRequestControlMiddleware setup. When request comes with Cache-Control header the value of max-age stored in context variable and can be used as ttl for cache by cache_control_ttl.
app=FastAPI()
app.add_middleware(CacheRequestControlMiddleware)
cache.setup(os.environ.get("CACHE_URI", "redis://"))
@app.get("/")@cache(ttl=cache_control_ttl(default="1m"), key="simple:{user_agent:hash}")asyncdefsimple(user_agent: str=Header("No")):
...
# HTTP GET /# Cache-Control: private, max-age=300# Cashews will cache response for 5 min (300 sec)
I have found that cache_control_ttl has no documentation and it's unclear on how and when to use it.
The text was updated successfully, but these errors were encountered: