简体   繁体   中英

Is there any way to clear cache from server farm?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM