Like Dmitry mentioned, you'll want to use the .Dependencies()
method to specify what content your query depends on (what should invalidate the cache).
There are some default cache dependencies that get set based on the current page, but not based on related pages. This means if you update the page using the content returned by this query, the cache will be cleared, however changes to any other page will not result in a cache eviction without using the .Dependencies()
method.
Here are the methods that the 2nd builder
parameter of the delegate passed to .Dependencies()
exposes:
IPageCacheDependencyBuilder<TPageType> Custom(string key);
IPageCacheDependencyBuilder<TPageType> Objects(IEnumerable<BaseInfo> objects);
IPageCacheDependencyBuilder<TPageType> ObjectType(string objectType);
IPageCacheDependencyBuilder<TPageType> PageOrder();
IPageCacheDependencyBuilder<TPageType> PagePath(string path, PathTypeEnum type = PathTypeEnum.Explicit);
IPageCacheDependencyBuilder<TPageType> Pages(IEnumerable<TreeNode> pages);
IPageCacheDependencyBuilder<TPageType> Pages(string className);
IPageCacheDependencyBuilder<TPageType> PageType(string className);
These don't cover all potential dependencies, but they handle the most common ones. You can use the .Custom()
method if you need to handle other dependencies (use this in combination with the 'cache dependency mechanism' link Dmitry supplied).
Also note that the first parameter to the delegate passed to .Dependencies()` is the result of the query, so you can set dependencies on the items your query returns (a pretty common use case).