Page Level Caching for reduced page load times

  • Updated

If you experience consistently long page load times on pages that are making large calls to the database using the Ektron API, see the solution in this KB article. 

To improve performance on pages that make large calls to the database you should implement a caching strategy. One part of a caching strategy is page level caching. The example supplied is for caching that is being utilized in tandem with the Ektron Framework API call TaxonomyManager.GetTree() . The intent of this API is to retrieve CMS items that have been categorized in Taxonomies. Depending upon the number of CMS items that one wishes to retrieve using this API, the call to the database can cause longer than desirable page load times. To reduce page load times you can implement a caching strategy so that after the initial page load the items retrieved will be cached. 

  TaxonomyManager taxMgr = new TaxonomyManager();
  long TaxonomyId = 100;   // Example Taxonomy id. 
  TaxonomyData td_AllData = new TaxonomyData(); //Taxonomy Data Object
  if (Cache["TaxData" + TaxonomyId] != null) //The Taxonomy Data has been previously cached
    td_AllData = (Ektron.Cms.TaxonomyData)Cache["TaxData" + TaxonomyId];
  else  //The Taxonomy Data has not been cached and will retrieve a taxonomy tree based on taxonomy Id. 
  td_AllData = taxMgr.GetTree(TaxonomyId, 3, true);
  Cache.Insert("TaxData" + TaxonomyId, td_AllData, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);
  //Once the taxonomy tree has been retrieved assign it to be cached for one hour.