IDistributed Cache
ASP 提供者.NET Core 应用领域旧的 ASP.NET framework 提供了独立的 ASP.NET 缓存,因此不能满足多服务器环境的需求。 它还不允许任何“自定义”第三方缓存提供程序插入,因此您只能使用其内置的独立 InProc 实现。
现在,新的 ASP.NET Core 已经解决了这个问题,并通过引入 IDistributedCache
处理多服务器环境中缓存的接口(例如负载平衡的网络场)。 这是什么 IDistributedCache
接口看起来像(请注意,这些方法中的每一个也有一个异步重载)。
namespace Microsoft.Extensions.Caching.Distributed
{
public interface IDistributedCache
{
// These methods also have overloads for “Async”
byte[] Get(string key);
void Refresh(string key);
void Remove(string key);
// Absolute expiration & sliding expirations possible
void Set(string key, byte[] value,
DistributedCacheEntryOptions options);
}
}
此外,ASP.NET Core IDistributedCache
接口在设计上是可插拔的,并允许您使用您选择的第三方提供商。 NCache 已经实施了一个提供者 IDistributedCache
你可以插入到你的 ASP.NET Core 应用无缝。 这样,您不必更改任何特定于 NCache.
IDistributedCache
Provider而且,这里是如何配置 NCache 作为 ASP 中的 IDistributed Cache 提供程序.NET Core 启动类:
public class Startup {
...
public void ConfigureServices (IServiceCollection services) {
...
services.AddNCacheDistributedCache();
...
}
...
}
IDistributedCache
它为您提供了很大的编程灵活性 IDistributedCache
接口,因为您现在可以插入您选择的任何第三方分布式缓存。 然而,这种灵活性的代价是 IDistributedCache
界面非常简单和基本。 因此,您无法从一些非常重要的分布式缓存功能中受益。
如果您预先付出一点额外的努力并使用 NCache 直接使用 API,您可以从各种各样的 NCache 高级缓存功能包括:
了解更多关于所有 NCache 功能 对你有用的。
NCache 是一个比 Redis 对于 .NET 应用程序,原因如下:
NCache 有以下三个版本:
NCache Open Source
NCache Professional
NCache Enterprise
有关每个版本的更多详细信息,请参阅 版本比较. 或者,选择以下选项之一。