Multiple Cache Blocks

Jun 26, 2012 at 7:45 AM

I have added multiple Cache blocks to workflow runtime

WorkflowRuntime workflowRuntime = new WorkflowRuntime();

ICacheManager cc1 = CacheFactory.GetCacheManager("ServiceCacheManager");


ICacheManager cc2 = CacheFactory.GetCacheManager("ExchangeServiceCacheManager");


I am retrieving all the services added to the Runtime 

ReadOnlyCollection allCache = workflowRuntime.GetAllServices();

How can I search for the CacheManager of type "ServiceCacheManager"

How to search my cache block in the list allCache?

Any help i appreciated.


Jun 27, 2012 at 6:54 AM
Edited Sep 1, 2012 at 2:08 PM

I don't think the approach presented will work since the CacheManager name is not associated with the CacheManager itself (but with the Enterprise Library Container).  I would recommend using a CacheManagerFactory and adding that as a service.  Then you can obtain a reference to the cache.  

   CacheManagerFactory cacheManagerFactory = new CacheManagerFactory();


Then you can obtain a reference to the factory and retrieve the cache of choice:

    var cacheManagerFactory = workflowRuntime.GetAllServices<CacheManagerFactory>().FirstOrDefault();
    var serviceCacheManager = cacheManagerFactory.Create("ServiceCacheManager");

    var exchangeServiceCacheManager = cacheManagerFactory.Create("ExchangeServiceCacheManager");

Randy Levy
Enterprise Library support engineer