+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / DynamicContent RadListView Cache Substitution

DynamicContent RadListView Cache Substitution

2 posts, 0 answered
  1. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    11 Jun 2015
    Link to this post

    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)
                    base.RenderContents(writer);
                else
                    this.DoPostCacheSubstitution();
            }
     
            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));
                cacheSubWrapper.RegisterPostCacheCallBack(this.Context);
            }
     
            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.
                this.DynamicContentListView.DataBind();
     
                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;
                 
            }

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    24 Jun 2015
    Link to this post
    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.

    Regards,
    Nikola Zagorchev
    Telerik
     
    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
     
2 posts, 0 answered