DynamicContent RadListView Cache Substitution

Posted by Community Admin on 04-Aug-2018 18:28

DynamicContent RadListView Cache Substitution

All Replies

Posted by Community Admin on 11-Jun-2015 00:00

I have an auto-generated dynamic widget that I did some customization on top of for the requirement of making items randomly sort every time a page refresh happens.

 I was hoping to be able to re-bind the data after it has been sorted within RenderCacheSubstitutionMarkup, but now realize that you cannot do that.  Is there  a way for me to pass the collection back through the RadListView to output the item templates or do I literally need to do something with StringBuilder to mockup up my entire template?


        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
            if (!FilterSuppliers)
        private void DoPostCacheSubstitution()
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("FilterSuppliers", Convert.ToString(this.FilterSuppliers));
            CacheSubstitutionWrapper cacheSubWrapper = new CacheSubstitutionWrapper(parameters, new CacheSubstitutionWrapper.RenderMarkupDelegate(RenderCacheSubstitutionMarkup));
        protected string RenderCacheSubstitutionMarkup(Dictionary<string, string> parameters)
            var output = String.Empty;
            // The following lines for DynamicContentListView do nothing as they are being cached and never called again
            this.DynamicContentListView.DataSource = null;
            this.DynamicContentListView.DataSource = this.Projects.RandomizeDynamicContent();
// RandomizeDynamicContent() does indeed work, but I cannot assign it this way.
            using (var sw = new System.IO.StringWriter())
                var htmlTextWriter = new System.Web.UI.HtmlTextWriter(sw);
                this.DynamicContentListView.RenderControl(htmlTextWriter); // this will be the same every time since the control is being cached and never rebound.  Can I force this somehow?
                output = sw.ToString();
            return output;

Posted by Community Admin on 24-Jun-2015 00:00

Hi Stacey,

If you want to use the cache substitution, you should return the markup to be rendered as a string. This way it could be substituted with the markup initially rendered and still keep the other page content cached. You can try creating a new control on the fly and rendering it in a an html text writer to get the markup. However, I will recommend using different approaches for your scenario.
One of them is to override the dynamic content view control and randomize the items shown. They will be cached by the output cache, but the cache will be invalidated ones a new item is added or modified. This will not exactly do what you want, since the content will not be random ordered on each request to the page, but you can do it on a database query level and take huge advantage of the output cache. You can also try invalidate the cache on session start, so when a user starts browsing the site the items are randomized.
Another option is to not cache the page at all, doing it on a page level from the advanced settings or from the response context from inside the widget. You can also use client side binding and retrieving the items using service, instead of doing it server side from the control.

Nikola Zagorchev

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items

This thread is closed