Use a cache substitution widget

To substitute the cache for a particular widget, you create a custom cache substitution widget and place it on the page. The widget utilizes the ASP.NET cache substitution. You create a static method that registers with the ASP.NET implementation of cache substitution. Inside this method, you must render the content of the widget.

Create the widget markup

Create a User widget with the following markup:

Implement the code behind

If the widget, you want to substitute, inherits from SimpleView, which in turn inherits from System.Web.UI.WebControls.WebControl, you can override the RenderContents(System.Web.UI.HtmlTextWriter writer) method. Inside, you call your own implementation for performing cache substitution.

When output cache is used on the page, you substitute it with the CacheSubstitutionWrapper in DoPostCacheSubstitution() method by forming a dictionary of parameters and passing it to a CacheSubstitutionWrapper.RenderMarkupDelegate that afterwards renders the correct markup.

IMPORTANT: Do not pass entire objects, such as a page, a control instance, property of the control, etc. This will cause serious memory leaks. When you need to pass a property value, you must use its string representation.

Following is a code sample of the code-behind file:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?