gpt4 book ai didi

azure - 无法使用Azure Function App使用内存缓存

转载 作者:行者123 更新时间:2023-12-02 23:24:26 25 4
gpt4 key购买 nike

我使用 Http 触发器创建了 Azure Function App,因为我想使用 system.runtime 命名空间中的内存缓存来缓存 token 。但是当我运行应用程序时,它会抛出错误 "System.Runtime.Caching: 无法加载文件或程序集 'System.Configuration.ConfigurationManager,Version=5.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51'。系统找不到指定的文件。”

我已确保项目中安装了准确的版本。这是 csproj 文件。

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.Runtime.Caching" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

这是我遇到问题的代码的最低版本。

public static class Function1
{
public static MemoryCache accessTokenCache = new MemoryCache("accessToken");
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
accessTokenCache.Add("123", "123", new CacheItemPolicy() { Priority = CacheItemPriority.Default });

return new OkObjectResult("");
}
}

最佳答案

上面的代码可以在 4.7.0 版本的 system.runtime.caching nuget 上正常工作。我现在已经降级以使其正常工作。

我也在github上发布了这个问题以供进一步跟进。 https://github.com/Azure/Azure-Functions/issues/1867

关于azure - 无法使用Azure Function App使用内存缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66708402/

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