-
Notifications
You must be signed in to change notification settings - Fork 5
Invalidate a cached route without hand-building a Request #332
Copy link
Copy link
Open
Labels
developer-experienceSurprising behaviour, missing warnings or unclear errors for library usersSurprising behaviour, missing warnings or unclear errors for library usersenhancementNew feature or requestNew feature or requesthttp-cacheThe @cache decorator, cache keys and Cache-Control handlingThe @cache decorator, cache keys and Cache-Control handling
Description
Activity
Metadata
Metadata
Assignees
Labels
developer-experienceSurprising behaviour, missing warnings or unclear errors for library usersSurprising behaviour, missing warnings or unclear errors for library usersenhancementNew feature or requestNew feature or requesthttp-cacheThe @cache decorator, cache keys and Cache-Control handlingThe @cache decorator, cache keys and Cache-Control handling
Problem
Invalidating a cached
GETroute from thePOST/PUThandler that changes the data needs a hand-built request. The documented recipe copies the ASGI scope and rewritesmethod,pathandquery_string:It is the most awkward snippet in the docs. The obvious call,
invalidate(request)with thePUTrequest itself, quietly returnsFalse, because it builds thePUTkey.Proposal
Add a helper that builds the key without a hand-made request. Two options:
await invalidate_path("/items/1", request=request, query=...), which takes host and scheme from the current request and usesGET;await read_item.invalidate(item_id=1).Either way it must honour
key_builderandvary, asinvalidate()does. It should also say clearly (warn or document) thatinvalidate()uses the method of the request it is given.