HttpContext.Current.Cache的范围

Scope of HttpContext.Current.Cache

如果我在同一台服务器上 运行 的多个网站中有以下行,应用程序写入同一缓存记录会不会有任何问题?

HttpContext.Current.Cache["SearchResults"] = myDataTable;

我知道文档说每个应用程序域有一个缓存,但我不太明白那是什么意思。

https://msdn.microsoft.com/en-us/library/system.web.httpcontext.cache There is one instance of the Cache class per application domain. As a result, the Cache object that is returned by the Cache property is the Cache object for all requests in the application domain.

应用程序域是一种在公共语言基础设施 (CLI) 中使用的机制(类似于操作系统中的进程),用于将执行的软件应用程序彼此隔离,以便它们不会相互影响。

因此,当您写入缓存时,它将存储在该应用程序域的内存中,如果您有网络花园(具有多个工作进程)或网络农场,则请求可能由 diff worker proc/node,那么那些 node/work proc 无法访问缓存,因为它们完全是 diff 应用程序域。

所以它说缓存是特定于单个应用程序域的,要解决上述问题,您需要寻找集中缓存存储。