我可以通过配置来切换。net缓存提供程序吗

时间:2021-11-15 05:46:32

Is there a way in .Net to switch out the Cache provider just like I would a membership provider, or role provider? I would like to keep the code untouched but switch to using a distributed cache like memcached or AppFabric.

在。net中,是否有一种方法可以像用户提供程序或角色提供程序那样切换缓存提供程序?我希望代码保持不变,但是切换到使用像memcached或AppFabric这样的分布式缓存。

All I am finding is how to switch out the output cache provider. This might be necessary, but it doesn't solve the issue of when Cache is called directly from within my code.

我所找到的只是如何切换输出缓存提供程序。这可能是必要的,但是这并不能解决从代码中直接调用缓存的问题。

I've found many libraries and they abstract Cache behind an interface, but this would mean I have to go to every spot in my code and inject the new abstraction. Also I am using PLINQO, which internally uses Cache.

我已经找到了许多库,它们在接口后面抽象缓存,但这意味着我必须访问代码中的每个位置并注入新的抽象。我还在使用PLINQO,它在内部使用缓存。

Is OutputCache the only thing I can switch out through configuration?

OutputCache是我唯一可以通过配置切换的东西吗?

Thank you in advance.

提前谢谢你。

1 个解决方案

#1


2  

You may take a look at the following presentation which explains the pre-.NET 4.0 state of caching and what .NET 4.0 brings in this respect. In .NET 4.0 the caching has been completely reworked into a separate assembly (System.Runtime.Caching) and rendered extensible. That's true for both object caching and page output caching. Unfortunately if you have current code that relies on the old Cache class this has to be changed as this class works with in-memory objects only.

你可以看一下下面的介绍,它解释了前题。NET 4.0缓存状态以及.NET 4.0在这方面带来了什么。在。net 4.0中,缓存已经被完全重新设计成一个单独的程序集(system . runtime.cache),并可扩展。对于对象缓存和页面输出缓存都是如此。不幸的是,如果您有依赖于旧缓存类的当前代码,那么必须对其进行修改,因为这个类只处理内存中的对象。

#1


2  

You may take a look at the following presentation which explains the pre-.NET 4.0 state of caching and what .NET 4.0 brings in this respect. In .NET 4.0 the caching has been completely reworked into a separate assembly (System.Runtime.Caching) and rendered extensible. That's true for both object caching and page output caching. Unfortunately if you have current code that relies on the old Cache class this has to be changed as this class works with in-memory objects only.

你可以看一下下面的介绍,它解释了前题。NET 4.0缓存状态以及.NET 4.0在这方面带来了什么。在。net 4.0中,缓存已经被完全重新设计成一个单独的程序集(system . runtime.cache),并可扩展。对于对象缓存和页面输出缓存都是如此。不幸的是,如果您有依赖于旧缓存类的当前代码,那么必须对其进行修改,因为这个类只处理内存中的对象。