Setting cache dependencies
Cache dependencies allow the application to automatically clear cached data when related objects are modified.
The system uses dummy cache keys to create dependencies between cached data and other objects. Dummy keys are cache items without any data that represent objects or groups of objects. When an object is modified, the system “touches” the corresponding dummy keys, which causes the cache to delete all items that depend on the given dummy keys.
Sample scenario
A page with the /Products alias path contains a Repeater web part with content caching enabled. The repeater displays a list of products (documents) placed under the Products page. When a visitor requests the Products page, the repeater loads the list of products from the database, and stores the data in the content cache. The cached data has a dependency on the node|corporatesite|/products|childnodes dummy key, which the system automatically creates. If a child document of the Products page is modified, the dummy key is touched, and the cache deletes the dependent data.
The following table shows which dummy cache keys are touched when objects are modified:
Object type |
Touched dummy keys |
Sample dummy key values |
Documents |
node|<site name>|<alias path>|<culture> + for all ancestors of the modified page: |
node|corporatesite|/home|en-us node|corporatesite|/|childnodes |
Objects |
<object type name>|all |
cms.user|all |
Metafiles |
metafile|<guid> |
metafile|1ced44f3-f2fc- … |
Document attachments |
cms.attachment|all |
cms.attachment|all |
Document relationships |
nodeid|<node id>|relationships |
nodeid|5|relationships |
Forum attachments |
forumattachment|<guid> |
forumattachment|1ced44f3-f2fc- … |
Avatars |
avatarfile|<guid> |
avatarfile|1ced44f3-f2fc- … |
Media files |
mediafile|<guid> |
mediafile|1ced44f3-f2fc- … |
Page templates |
template|<id> |
template|12 |
Custom table data records |
customtableitem.<custom table code name>|all |
customtableitem.customtable.sampletable|all |
Adding custom cache dependencies
You can set custom cache dependencies for the following types of cache:
- Full output cache of pages (add the Output cache dependencies web part onto the page)
- Partial output cache of web parts or controls (Partial cache dependencies property)
- Content cache of web parts or controls (Cache dependencies property)
- Cached data in custom code
Create the dependencies by typing the names of dummy cache keys into the appropriate Cache dependencies property. Each dummy key must be on a separate line when entering dependencies in the web part properties dialog. The system automatically clears the related cache when the specified dummy keys are touched (i.e. when the corresponding objects are modified).
Examples
Scenario: You have a web part displaying information about users. You need to clear the web part’s partial output cache whenever one of the user’s data is modified.
Solution: Add the cms.user|all dummy key into the web part’s Partial cache dependencies property. The system touches this dummy key whenever the data of a user in the system changes.
Scenario: You have a web part displaying information about one specific user — the administrator (UserID is 53, UserGuid is 849711D0-739D-412E-92B6-FE40EDCADC4A). You need to clear the web part’s partial output cache when the administrator’s user account data is modified.
Solution: Add any of the following dummy keys into the web part’s Partial cache dependencies property:
- cms.user|byid|53
- cms.user|byname|administrator
- cms.user|byguid|849711D0-739D-412E-92B6-FE40EDCADC4A
Scenario: You have a web part displaying a list of news articles. The web part loads the data from all CMS.News documents on the website. The site’s code name is NewsSite. You need to clear the web part’s partial output cache when any of the news documents is updated.
Solution: Add the nodes|newssite|cms.news|all dummy key into the web part’s Partial cache dependencies property.