InMemory cache storage persistence with fluent configuration

Topics: Caching Application Block
May 5, 2010 at 12:53 PM

Hi Experts,

I am trying to use the default in memory storage. If I use a configuration file, different instances of a class using the enterprise caching block works as expected. If I cache something in one instance, another instance can access the instance can retrieve the cached object.

However, using the new Fluent Configuration API in v5, I am setting up my configuration like this

ConfigurationSourceBuilder configBuilder = new ConfigurationSourceBuilder();                    


DictionaryConfigurationSource configSource = new DictionaryConfigurationSource();                    


EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

And I access my cache block like this CacheManager = CacheFactory.GetCacheManager(mCacheManagerName);

Since we're actually creating a new container based on the configBuilder, a instance of a class accessing the cache will not be able to retrieve an object added by another instance using the cache...or so it seems to me.

Can anyone help?


May 5, 2010 at 6:06 PM

The only time when you'd get two different cache managers is if you get one before you reconfigure, and then get it again after you configure. The cache manager itself is a singleton inside the container, so every time you request it you'll get the same instance, so it should be doing what you want.

Are you actually seeing different instances returned? Is so, it's a major bug and not something we've seen in our testing.


May 6, 2010 at 9:25 AM

I got around the problem by having my own unity container.

I expected if I am using the CacheBlock of the same name, that I would get the same instance. Since I was testing the fluent configuration API, I was actually reconfiguring every time I needed the cache block. 

So, I think everything is working correctly.