我已在应用程序中实现了OutputCache并且工作正常,但由于我已将该位置指定为服务器,并且应用程序在服务器场(2台服务器)中运行,因此当我清除缓存时,它仅从一台服务器清除一度。我已经考虑过指定服务器位置(硬编码),以便缓存将存储在一个地方,并且在必要时可以轻松清除。 那么,有没有办法在OutputCache中硬编码location属性的服务器名称?还是从webconfig文件?
webconfig中的声明
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="Cache10Minutes"
duration="300"
location="Server"
varyByParam="none"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
相关页面(页眉)中的定义
<%@ OutputCache CacheProfile="Cache10Minutes" Duration="300" Location="Server" VaryByParam="none"%>
要清除按钮上的缓存
HttpRuntime.UnloadAppDomain()
或者从客户端更新时从数据库创建触发器。这可以清除两台服务器的缓存吗?如果我的想法错误或不够清楚,请纠正我,我很困惑。请指教。
答案 0 :(得分:1)
据我所知,输出缓存仅适用于每台服务器。您可以实现自己的OutputCacheProvider
并实现自己的缓存机制:OutputCacheProvider Class, MSDN
或者也许使用AppFabric的分布式缓存:How to: Configure the AppFabric Output Cache Provider for ASP.NET 。请注意,微软明年将结束对AppFabric for Windows Server的支持Microsoft AppFabric 1.1 for Windows Server Ends Support 4/2/2016