gpt4 book ai didi

c# - ConcurrentDictionary 对象持续多长时间?

转载 作者:行者123 更新时间:2023-12-01 20:11:10 52 4
gpt4 key购买 nike

我在 Azure 应用服务上使用 MVC 5、ASP.NET 4.7

我正在使用 ConcurrentDictionary 对象来保存数据,以保存对数据源的多次调用。

关于其行为的几个问题:

1) 填充后,它将持续供同一 Web 应用程序的多个用户访问。我对么?因此,只有网站重新启动后的第一个用户才会受到性能影响。

2)它会持续多久?是直到另一次池刷新或站点重新启动,还是存在某种形式的非事件超时?

提前致谢。

编辑:

public class myCache
{
private static readonly ConcurrentDictionary<int, string> myCacheDictionary = new ConcurrentDictionary<int, string>();

public static async Task populateCache()

最佳答案

1) Once it has been populated, then it will persist for multiple users of the same web application to access. Am I correct? So only the first user after a web site restart gets a performance hit.

是的,static 关键字意味着只要应用程序在内存中,它就会一直保留,除非您以编程方式将其清除。无论用户、线程、同步上下文等如何,每个请求都将使用相同的实例。

2) How long does it persist for? Is it until another pool refresh or site restart, or is there some form of inactive timeout?

除非您以其他方式对其进行编程,否则它会一直存在,直到应用程序池刷新或站点重新启动为止。

如果您将 MemoryCache 类用于缓存目的,您可能会对它感兴趣。它可以让您设置策略,以便在特定时间后或检测到内存开始不足时清除其数据。

关于c# - ConcurrentDictionary 对象持续多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49656229/

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