Cache with Keydependency Example
The cache macro is able to generate AIM relations so that cache is automatically flushed when related items shown in the cache result would change. For instance, a Sitemap is perfectly cacheable because it will be rebuilt whenever a change occurs in one of the listed folders.
Sometimes however, the cached result depends on external parameters, such as query strings, or userprofile settings (1.2+). In these cases, you can specify those parameters in the KeyDependencies collection.
In the example shown here, the code of a ContentType is passed over the querystring. This code is used in a cached SqlQuery macro.
Smartsite SXML | Copy Code |
---|---|
<se:cache> <se:parameters> <se:parameter name="keydependencies"> <se:collection> <se:member name="ct"> {request.query(ct)} </se:member> </se:collection> </se:parameter> <se:parameter name="xml"> <se:sqlquery sql="select nr, title from {channel.view()} where contenttype=?" params="{contenttype.getnumber(request.query(ct, default='CWP'))}" rowformat="{html.div(this.field(title))}" /> </se:parameter> </se:parameters> </se:cache> |