Posted by: glittermonkey | August 4, 2008

Configure EnterpriseLibrary Cache without app.config file

The basic approach to configuring the EnterpriseLibrary Cache application block from code, without using an app.config file.

private void TestCacheConfiguration()
{
 CacheManagerFactory cacheFactory = new CacheManagerFactory(GenerateConfiguration());
 cache = cacheFactory.Create(“Sample Cache Manager”);
}

private static DictionaryConfigurationSource GenerateConfiguration()
{
 DictionaryConfigurationSource sections = new DictionaryConfigurationSource();
 sections.Add(CacheManagerSettings.SectionName, GenerateDefaultCacheManagerSettings());
 return sections;
}

private static CacheManagerSettings GenerateDefaultCacheManagerSettings()
{
 CacheManagerSettings settings = new CacheManagerSettings();
 settings.BackingStores.Add(new CacheStorageData(“inMemory”, typeof(NullBackingStore)));
 settings.CacheManagers.Add(
  new CacheManagerData(“Smart Alert Cache Manager”,
   10000,
   1000,
   100,
   ”inMemory”));
 return settings;
}


Leave a response

Your response:

Categories