gpt4 book ai didi

c# - 在 ASP.NET 5/MVC 6 中使用 IDistributedCache 和 Redis - 类型或命名空间 'Microsoft.Caching' 不存在

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:18 26 4
gpt4 key购买 nike

我正在尝试在 MVC 6 中使用 Redis 缓存,但我无法构建我的项目。

我遵循了 https://github.com/aspnet/Caching/tree/dev/samples 中的示例- 有一个 IDistributedCache 示例和一个 Redis 示例。但是,这并不完全清楚,因为 Redis 示例不是 Web 应用程序。

我的 project.json 依赖项中有这个:

    "Microsoft.Framework.Cache.Memory": "1.0.0-beta3",
"Microsoft.Framework.Caching.Distributed": "1.0.0-*",
"Microsoft.Framework.Caching.Redis": "1.0.0-*",

我用它来获取我的包裹:

kpm install Microsoft.Framework.Caching.Distributed

kpm install Microsoft.Framework.Caching.Redis

两个命令都有效并返回了 OK。

在我的初创公司中,我正在尝试以下操作:

 services.AddSingleton<IMemoryCache, MemoryCache>();
services.AddSingleton<IDistributedCache, RedisCache>();

尝试构建或运行时,给出的错误是:

Startup.cs(10,27): error CS0234: The type or namespace name 'Caching' does not exist in the namespace 'Microsoft.Framework' (are you missing an assembly reference?) Startup.cs(11,27): error CS0234: The type or namespace name 'Caching' does not exist in the namespace 'Microsoft.Framework' (are you missing an assembly reference?) Startup.cs(25,35): error CS0246: The type or namespace name 'IDistributedCache' could not be found (are you missing a using directive or an assembly reference?) Startup.cs(25,54): error CS0246: The type or namespace name 'RedisCache' could not be found (are you missing a using directive or an assembly reference?)

现在显然我有错误的引用 - 但正确的引用是什么?我是直接从示例中复制 namespace 吗?我尝试切换到 Microsoft.Cache.Distributed 但这也不起作用(并且与 github 冲突)

我觉得这与没有正确的 K 版本有关,也许这就是出路 - 升级到最新版本。 Framework.Cache.Memory 和 Framework.Cache.Distributed 之间存在不匹配,我看到了与 namespace 更改相关的 github 评论。

如果有人能指出走出这个迷宫的路,非常感谢。

最佳答案

The below answer applies for 1.0.0-beta4 release of caching library which corresponds to here: https://github.com/aspnet/Caching/tree/1.0.0-beta4

IMemoryCacheMicrosoft.Framework.Caching.Memory 命名空间和 IDistributedCache 下在 Microsoft.Framework.Caching.Distributed 命名空间下。

依赖关系看起来像这样:

"dependencies": { 
"Microsoft.Framework.Caching.Memory": "1.0.0-beta4",
"Microsoft.Framework.Caching.Distributed": "1.0.0-beta4",
"Microsoft.Framework.Caching.Redis": "1.0.0-beta4"
}

因此,Microsoft.Framework.Cache.MemoryMicrosoft.Framework.Caching.Memory

关于c# - 在 ASP.NET 5/MVC 6 中使用 IDistributedCache 和 Redis - 类型或命名空间 'Microsoft.Caching' 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30325970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com