This is a util lib that helps create and handle the xkey headers used by xkey vmod in Varnish to support secondary hashes to objects.
- Add lib as a dependency to your build.gradle file
dependencies {
include 'com.github.tineikt:xp-lib-perfectcache-headers:1.0.0'
}
- Add response filter to your
site.xml
<site>
...
<filters>
<response-filter name="perfectCacheHeaders" order="10"/>
</filters>
</site>
Require it in your JavaScript code.
import { pch } from '/lib/tineikt/perfectcache-headers';
Create a new perfect cache header object.
const cacheHeaders = new pch(name);
name
should be something unique for the complete request. If used in a part we could use the path to the component.
We can then populate this cache by adding relations to it in our controller.
cacheHeaders.add(content._id);
cacheHeaders.add(content.data.conRelatedContents);
Then all we have to do is make sure we return the headers in the response.
const headers = cacheHeaders.getHeader();
return {
headers,
body: freemarker.render(viewFile, model)
};
The xp-content-path
header should also be set on page controllers with the value of the path to the content.
This header is used by the xp-app-perfectcache-purger to ban whole whole sites/trees.
headers['xp-content-path'] = encodeURI(content._path); // if paths contain åæø or other chars invalid in header values.
Returns a simple header ready to be returned in response
{
headers: {
pch-name: 'con-ce5dc0e7-0e28-47fc-b4a6-4d81727f00e7,cat-104c0db2-aa53-411c-8f6a-9213947d13d9'
}
}
Adds a single content to the header
Remove a single content from the header
Util function to support media mixin and add selected image or video content by passing media node
Util function to support link mixin and add selected target content if internal link
Util function iterates a region to find any fragment in that region
Util function using the list config to fetch content, section and tags affecting the resulting resultset.