We have CMS content that is all served through a single proxied API (ex. /api/CMS?content=123
) and want to be able to clear specific content blocks, without clearing the entirety of the /api/CMS
cache. Is it possible to do a cache clear on the value of a query string parameter? The UI seems to not allow it, so wondering if there is an alternate way.
You can use surrogate keys by setting the x-0-surrogate-key
upstream response header
and then read in the query param - so for /api/CMS?identifier=blah
you would do:
.get('/api/CMS', ({ setUpstreamResponseHeader, cache }) => {
.... cache stuff ....
setUpstreamResponseHeader('x-0-surrogate-key', 'cms_slot=${query:identifier}')
})
Which will then set the surrogate key for requests based on the value of that query parameter