仅为匿名配置ASP.NET缓存?

时间:2010-02-25 03:20:08

标签: asp.net caching

我正在寻找一种仅为匿名用户配置缓存的方法。我希望这样做的原因是当用户登录并且他们创建内容时他们不会立即看到内容。在我们的旧系统(linux / php / mysql)中,我们将其配置为仅缓存匿名用户,这不是问题。

现在我们在web.config中有像这样的

的缓存设置
<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="High" duration="60" varyByParam="*" enabled="true"/>
      <add name="Medium" duration="30" varyByParam="*" enabled="true"/>
      <add name="Low" duration="10" varyByParam="*" enabled="true"/>
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

我知道我可以添加一个像this post这样的varyByCustom =“userName”。但这并不能解决我的问题。它仍然缓存用户登录并存在同样的问题。

2 个答案:

答案 0 :(得分:1)

正如James所说,以某种方式使缓存失效可能会更好。

这样您就可以为所有匿名用户维护缓存。为什么不提高管理员的响应能力,他们毕竟可能最常使用应用程序?

你看过SQL缓存依赖吗?这样,当存储内容的表被更改时,缓存就会失效。

http://msdn.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx

答案 1 :(得分:0)

当用户使用下面显示的方法对页面进行更改时,您可以从缓存中删除/过期页面:

HttpResponse.RemoveOutputCacheItem("/PageJustUpdated.aspx");