ASP.Net Cache是​​否在不同的用户会话之间共享?

时间:2020-12-19 16:49:32

In a page if I do the following:

在页面中,如果我执行以下操作:

Cache["key"] = myObject;

Cache [“key”] = myObject;

Is that cached object available for requests that are for other users?

该缓存对象是否可用于其他用户的请求?

3 个解决方案

#1


14  

Yes. The cache is Application level, and all users are in the same application.

是。缓存是应用程序级别,所有用户都在同一个应用程序中。

If you need a per-user Cache you could use the Session, but that's not quite the same. The cache allows the framework to automatically expire items in a different way from the session. If you want the cache behavior on a per-user basis (not necessarily a good idea) you could build the user's ID into part of your key for the main cache.

如果您需要每用户缓存,您可以使用会话,但这并不完全相同。缓存允许框架以与会话不同的方式自动使项目过期。如果您希望基于每个用户的缓存行为(不一定是个好主意),您可以将用户的ID构建为主缓存的密钥的一部分。

#2


9  

Yes it is available for all users on the same server. However, if you are running a farm, it will only be available to users that are using the server in which the data was added to cache.

是的,它适用于同一服务器上的所有用户。但是,如果您正在运行服务器场,则只有使用将数据添加到缓存的服务器的用户才能使用它。

#3


1  

Cache is good for per AppDomain. The single application like web Applicaiton usually remain in the single AppDomain. But cache can not be shared between something like web app and web service.

缓存适用于每个AppDomain。像Web Applicaiton这样的单个应用程序通常保留在单个AppDomain中。但是,无法在Web应用程序和Web服务之间共享缓存。

#1


14  

Yes. The cache is Application level, and all users are in the same application.

是。缓存是应用程序级别,所有用户都在同一个应用程序中。

If you need a per-user Cache you could use the Session, but that's not quite the same. The cache allows the framework to automatically expire items in a different way from the session. If you want the cache behavior on a per-user basis (not necessarily a good idea) you could build the user's ID into part of your key for the main cache.

如果您需要每用户缓存,您可以使用会话,但这并不完全相同。缓存允许框架以与会话不同的方式自动使项目过期。如果您希望基于每个用户的缓存行为(不一定是个好主意),您可以将用户的ID构建为主缓存的密钥的一部分。

#2


9  

Yes it is available for all users on the same server. However, if you are running a farm, it will only be available to users that are using the server in which the data was added to cache.

是的,它适用于同一服务器上的所有用户。但是,如果您正在运行服务器场,则只有使用将数据添加到缓存的服务器的用户才能使用它。

#3


1  

Cache is good for per AppDomain. The single application like web Applicaiton usually remain in the single AppDomain. But cache can not be shared between something like web app and web service.

缓存适用于每个AppDomain。像Web Applicaiton这样的单个应用程序通常保留在单个AppDomain中。但是,无法在Web应用程序和Web服务之间共享缓存。