Activation error occured while trying to get instance of type ICacheManager, key “Cache Manager”

前端 未结 1 1513
旧巷少年郎
旧巷少年郎 2021-01-05 05:02

I seem to have hit a wall here and would appreciate some help from anyone who is able to on this one. I am not exactly sure what the error message below means. I am using th

1条回答
  •  萌比男神i
    2021-01-05 05:34

    The Caching Application Block requires some configuration information to be present in the app/web.config before it can be used (AFAIK, unfortunately it is tough to find documentation stating otherwise). Without that configuration info, the following code will cause that same exception to be thrown as you are seeing:

    var cm = CacheFactory.GetCacheManager("MyCacheManager");
    

    In order to get a CacheManager, you need to define the CacheManager in your app.config or web.config:

    
        
            

    Once you add the configuration values, you should be able to get a valid CacheManager from the CacheFactory. The post also has some more information that might help you.

    It is worth noting that if you are using .NET 4.0, for non web apps you can use MemoryCache (in the System.Runtime.Caching namespace) which provides similar functionality but does not require all of this configuration. And for web apps you can of course use the Cache class in System.Web.Caching.

    0 讨论(0)
提交回复
热议问题