More in this section

Forums / General Discussions / Caching enabled for all the pages in single place

Caching enabled for all the pages in single place

4 posts, 0 answered
  1. praveen
    praveen avatar
    4 posts
    Registered:
    23 Dec 2010
    25 Jan 2011
    Link to this post

    I know that to set the caching for a page I need to go to page -> Title & Properties -> Advanced Options -> Enable Caching

    But I have to enable caching to almost 100 pages. I have to enable caching for all 100 pages then I will have to visit 100 pages and set caching option. Instead is there a mechanism by which I can set caching options enabled for all the pages in single place.

    Any suggestions?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Jan 2011
    Link to this post
    Hello praveen,

    The PageData has a property CacheOutput which you can set to true programmatically for all pages. You can use Pages facade

    sample

    using(var fluent = App.WorkWith())
          {
              fluent.Pages().ForEach(p => p.Page.CacheOutput = true);
          }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. praveen
    praveen avatar
    4 posts
    Registered:
    23 Dec 2010
    27 Jan 2011
    Link to this post

     I tried your code by placing it at “Application_Start” event but it used to give me “Object reference not found error” then I moved it to one of my page again I used to get “Object reference not found error”.

    So I had used following code:

    var pages = App.WorkWith().Pages()
                        .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                        .Where(page => page.ApprovalWorkflowState == "Published")
                         .Get();
                        foreach (var page in pages)
                        {
                            page.Page.CacheOutput = true;
                        }

     

    To execute this code I need the user to have some permissions and I cannot assign permissions to all the users visiting my site. So how do I enable global caching.

    Please suggest.

     

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    28 Jan 2011
    Link to this post
    Hi praveen,

    You are getting a null reference, because some object from your expression returns null. Also p.Page is a PageData and if you have a group pages you will get this exception. Also you can execute the code from a user control instead of Application_Start which is called inside Global.asax

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered