.net-core - 当我们有 IDistributedCache 时,为什么要使用 IMemoryCache?

标签 .net-core

.Net Core 为两个接口(interface)( MemoryCacheDistributedMemoryCache )提供内存实现,但假设我们有一个可用的 IDistributedCache我们的应用程序的实现。

什么时候仍然使用 IMemoryCache 有意义.在什么情况下它比在分布式缓存中缓存数据更有帮助或更受欢迎?

最佳答案

我正在寻找相同的内容,并在 github 问题中找到了答案:

They have fundamentally different semantics. MemoryCache can store live objects, the distributed cache can't, objects have to be serialized. The distributed cache can be off box and calls to it may fail or take a long time so getting and setting should be async, the MemoryCache is always in memory and fast. The distributed cache can be disconnected from the store so the interface should account for that.


https://github.com/aspnet/Caching/issues/220#issuecomment-241229013

关于.net-core - 当我们有 IDistributedCache 时,为什么要使用 IMemoryCache?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59791959/

相关文章:

c# - 尝试通过 C# 中的多线程从两个不同的数据库表中获取值

.NET(标准、核心和框架): Developing Cross Platform Applications

c# - 在 Linux 上使用 .NET Core 2.0 进行 Process.Start

c# - 除了相应的 `foreign key Id` 之外,我还应该定义 `navigation property` 属性吗?

c# - .NET Core 依赖注入(inject)向后兼容 .NET Framework?

asp.net-core - 如何在 AspNetCore 2.2 NLog 中关闭 Microsoft 日志

c# - 我应该在哪里启动 ASP.NET Core 中的持久后台任务?

.net-core - System.PlatformNotSupportedException : 'Operation is not supported on this platform.' when upgrading ServiceStack to .netcore 2.0

c# - 在 .net core 应用程序中自托管 HTTP(s) 端点而不使用 asp.net?

.net-core - .net 核心中的 XSD/架构验证解决方法?