gjshah7254
5/9/2014 - 5:05 AM

Caching in kentico's Custom Code

Caching in kentico's Custom Code

using CMS.SiteProvider;
using CMS.GlobalHelper;
 
private void CachingExample()
{
  DataSet data = null;
 
  // Cache the data for 10 minutes with key "mykey"
  using (CachedSection<DataSet> cs = new CachedSection<DataSet>(ref data, 10, true, null, "mykey"))
   {
      if (cs.LoadData)
       {
           data = UserInfoProvider.GetAllUsers(); // Get data from database
           cs.CacheDependency = CacheHelper.GetCacheDependency("somekey"); // Cache dependency
           cs.Data = data; // Save data to cache
       }
   }
}