By default, the Sitefinity CMS output cache does not vary by query string parameters. This means that if a cache version of the page is found, Sitefinity CMS will serve it, regardless of the query string portion f the page URL.
If you are using query strings in your custom code, and would like to have the page cache vary by the query string parameters you must configure this explicitly. Sitefinity CMS provides two ways of handling this:
NOTE: There is no need to use QueryStringGet in the cases where you have disabled output cache for the page, or have configured varyByParams="*" in your output cache profile.
If you want Sitefinity CMS to automatically register output cache variations for the query string parameters you use, you should substitute usages of the standard HttpRequest.QueryString[key] ASP.NET approach with the Sitefinity CMS QueryStringGet() extension method from the Telerik.Sitefinity.Web namespace . The method accepts the query string parameter name as argument, so you can easily switch to this approach. The following example demonstrates usage of the QueryStringGet extension method:
In addition to automatically registering cache variations for your query string parameters, the QueryStringGet extension method enables you to use a CacheVariationParamValidator. The CacheVariationParamValidator provides a mechanism to register cache variations for the query string parameter values. Inside the validator logic you can specify for which values of the query string parameter Sitefinity CMS should serve a new version of the page. This mechanism is very useful in case you want to enable cache variations for certain query string parameters, but would like to limit the values for which Sitefinity CMS creates a new cached version of the page.
To use the validator mechanism you must create a class and inherit from the CacheVariationParamValidator abstract class. Inside your class you must implement the Validate method, which accepts the query string parameter value as argument. Inside your Validate method logic you can compare the parameter value against a predefined list of allowed values. Finally, you must specify the type of your validator, when using the generic overload of the QueryStringGet extension method. For example:
Sign up for our free beginner training. Boost your credentials through advanced courses and certification. Register for Sitefinity training and certification.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important