API Questions on Kentico API.
Version 6.x > API > Caching in custom code View modes: 
User avatar
Member
Member
nicolas.juteau-nexun - 4/13/2012 9:22:43 AM
   
Caching in custom code
In this post I am refering to this page in the documentation.

It states:

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

}

}

}

Why are there two distincts key used in this code snippet? mykey and somekey are used. Is there something I am missing here?

What is the relation between the newly added cached section and the cache dependency?

The code works just fine, I am just wondering why two different keys are used in this case.

Any tip would be very appreciated.

Regards,

User avatar
Member
Member
kentico_michal - 4/16/2012 5:07:31 AM
   
RE:Caching in custom code
Hi,

I would recommend you to go through the following blog that explains cache and cache dependencies in detail. Especially, the section called Cache dependencies and API could give you more information: Deep dive - Cache dependencies.

Best regards,
Michal Legen