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

Forums / Developing with Sitefinity / Defaulting Enable Cache to true and cache expiration value

Defaulting Enable Cache to true and cache expiration value

2 posts, 0 answered
  1. Krister
    Krister avatar
    1 posts
    Registered:
    12 Jan 2006
    26 Jun 2009
    Link to this post
    Is there a way to customize the default for every page to default the cache parameter to True?

    Is there a way to change the default cache duration setting from 120 seconds to some larger value?

    Is there a way to make these settings for multiple pages at one time? (after doing this manually for about 75 pages, I'm thinking I probably should have waited to see the answer to this question)  If there's an answer, then it will save me the time of doing it manually for the remaining 100 pages, though :)

    Krister
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    26 Jun 2009
    Link to this post
    Hello Krister,

    You can control the global values (duration and sliding expiration) for page caching in telerik/framework/caching section in the the web.config:
    <telerik> 
      ... 
      <framework> 
        <caching defaultProvider="memoryCache"
          <providers> 
            <add name="memoryCache" type="Telerik.Caching.MemoryCachingProvider, Telerik.Framework"/> 
            <add name="ASPNET" type="Telerik.Caching.AspNetCachingProvider, Telerik.Framework"  
            duration="120" slidingExpiration="true"/> 
          </providers> 
          <cacheDependency mode="InMemory"/> 
        </caching> 
     

    But there is no a global value for applying Enable Caching for all pages. You should do it with the user interface.
    Or, you can write a code, which uses the API to iterate through the pages and enables caching for each page, i.e.:
                // This code will enable caching for each page in the WebSite 
                Telerik.Cms.CmsManager manager = new Telerik.Cms.CmsManager(); 
                foreach (Telerik.Cms.ICmsPage page in manager.GetPages()) 
                { 
                    Telerik.Cms.ICmsPage pageForEdit = manager.GetPage(page.ID, trueas Telerik.Cms.ICmsPage; 
                    if (pageForEdit != null 
                        && (pageForEdit.PageType == Telerik.Cms.CmsPageType.Normal)) 
                    { 
                        pageForEdit.RequireCaching = true
                        manager.SavePage(pageForEdit); 
                    } 
                } 
                return

    The above is related to the existing pages in the site.
    However, you can customize the default values of some page properties, so the newly created pages will use your default values. In, order to do this, you should declare telerik/cms/pages/defaultProperties element in the web.config:
    <cms defaultProvider="Sitefinity" ...> 
      <pages> 
        <defaultProperties requireCaching="true" navigable="true" disableViewState="false" requireSSL="false" /> 
      </pages> 

    Where, you can see the page properties, which default values you can customize. All except the requireCaching attribute are set with their default values and you can skip them from the configuration.

    Hope this is helpful.

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered