Is there any way to clear cache from server farm?

时光毁灭记忆、已成空白 提交于 2019-12-12 05:34:16

问题


I have implemented OutputCache in an application and it works fine, but since I have specified the location as server, and the applications runs in server farm (2 servers) , when I clear the cache, it clears only from one server at one time. I have thought about specifying a server location (hardcode), so that the cache will be stored at one place and can be easily cleared when I have to. So, is there any way to hardcode server name for the location attribute in OutputCache? Or from webconfig file?

Declaration in webconfig

<system.web>
<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="Cache10Minutes"
           duration="300"
           location="Server"
           varyByParam="none"/>
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

Definition in related page (page header)

<%@ OutputCache CacheProfile="Cache10Minutes" Duration="300" Location="Server" VaryByParam="none"%>

To clear cache on button click

HttpRuntime.UnloadAppDomain()

Or what about creating a trigger from database on update from client. Can this clear cache from both the servers? Correct me if my idea is wrong or not clear enough, I'm confused. Please advice.


回答1:


As far as I know output cache is per server only. You can implement your own OutputCacheProvider however and implement your own caching mechanism: OutputCacheProvider Class, MSDN

OutputCacheProvider for Redis

Or maybe use distributed cache with AppFabric: How to: Configure the AppFabric Output Cache Provider for ASP.NET . Be aware though that Microsoft is ending support for AppFabric for Windows Server next year Microsoft AppFabric 1.1 for Windows Server Ends Support 4/2/2016



来源:https://stackoverflow.com/questions/29816268/is-there-any-way-to-clear-cache-from-server-farm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!