Caching enabled for all the pages in single place
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?
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);
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.
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