Cache Manager in Caching Application Block

Topics: Caching Application Block
Jan 7, 2010 at 6:41 PM

Hi All,

I have been using asp web cache in all my prior application developments. I am looking into Ent. Lib caching application block which seems pretty interesting.

However, I have need some clarifications on how the cache managers work?

1- What is the purpose of having multiple cache managers, is it to partition cahing items ? I am used to have only a single cache manager (similar to ent. lib. default cache manager)?

2- Does each cache manager maps to an individual hash table ? or they are all going to be stored in one hash table?  

3- If I only use the Null storage option (no backing store) does it make a difference if I use multiple cache managers?

 

Thanks,

Robert B.

Jan 8, 2010 at 1:22 AM

1. The purpose of having multiple cache managers is if you want to use different backing stores like the in memory (default), database, or isolated storage.  Or you may just simply want to have different cache managers to group the items you want to cache.

2. Yes, they are stored in different hash tables.

3. Yes it does as explained by the answer in number 2.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jan 8, 2010 at 1:33 AM

Thanks Sarah. Your answers were very helpful.

My next question is to figure out which approach is better?  Having a) a single Cache Manager for each object type ? b) one single cache manager that handles multiple object types?

I understand it could depend on the situation, but right now I am in a situation that I have to decide to either rule out having different object types in one cache manger or not!

is there any significant downsides to each of these approches?

 

Thanks alot,

Robert B.

 

 

Jan 8, 2010 at 2:18 AM
Edited Jan 8, 2010 at 2:18 AM

I'm thinking that at a certain point, it'll be faster to retrieve multiple cache managers with smaller number of items in their hashtable rather than having a single cache manager containing all of your cached items.  However, I'm not sure what is the range of difference of the number of items in a cache which would justify the performance.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Apr 9, 2010 at 9:38 AM

I've used a cache manager for every business object. Now I'm facing the following problem: Any idea on how to get the list of cache managers from the the .config file?

To better explain, I'm interested in having the list of "name" attributes (in red) from the following configuration:

<cacheManagers>

<add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.ServiceRequestUser"/>

      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.Text"/>
      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.UserIdUsername"/>
      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.Operation[]"/>
    </cacheManagers>

 

    <cacheManagers>

      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.ServiceRequestUser"/>

      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.Text"/>

      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.UserIdUsername"/>

      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" name="ServiceRequestVolatileServices.Operation[]"/>

    </cacheManagers>

 

 

Any help will be appreciated.

 

Thanks and ciao

Antonio

Apr 12, 2010 at 12:46 AM

Here's a sample code:

IConfigurationSource entLibConfig = ConfigurationSourceFactory.Create();
CacheManagerSettings cacheSettings = (CacheManagerSettings)entLibConfig.GetSection(CacheManagerSettings.SectionName);
foreach (var cacheManager in cacheSettings.CacheManagers)
{
       Console.WriteLine(cacheManager.Name);
}

 

This code gets the cachemanagers from the default configuration source you specified in the Configuration Sources section.  If you don't have any configuration source other than your app.config/web.config file, it automatically gets the information from there.  If you need to specify a different .config file that is not specified in your configuration sources section, you can new up a FileConfigurationSource specifying the filename as parameter to the constructor.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com