简体   繁体   English

有什么方法可以清除服务器场中的缓存?

[英]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. 我已经在一个应用程序中实现了OutputCache,并且工作正常,但是由于我将该位置指定为服务器,并且这些应用程序在服务器场(2台服务器)中运行,因此当我清除缓存时,它一次只能从一台服务器清除。 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? 因此,有什么方法可以硬编码OutputCache中location属性的服务器名称吗? Or from webconfig file? 还是从webconfig文件?

Declaration in webconfig 在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并实现自己的缓存机制: OutputCacheProvider类,MSDN

OutputCacheProvider for Redis Redis的OutputCacheProvider

Or maybe use distributed cache with AppFabric: How to: Configure the AppFabric Output Cache Provider for ASP.NET . 或将分布式缓存与AppFabric一起使用: 如何:为ASP.NET配置AppFabric输出缓存提供程序 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 请注意,尽管微软明年将停止对Windows Server的AppFabric的支持Microsoft Windows Server的AppFabric 1.1的支持将在2016年4月2日终止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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