同花顺HttpRuntime.Cache跨越上IIS web服务器的所有工作进程对象 [英] Flush HttpRuntime.Cache objects across all worker processes on IIS webserver

查看:1012
本文介绍了同花顺HttpRuntime.Cache跨越上IIS web服务器的所有工作进程对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络园模式IIS 7的建立运行一个asp.net web应用程序。我想清楚了使用单步跨所有工作进程运行时的缓存项。我可以设置一个数据库,关键值,但是这将意味着一个线程执行上的每个工作进程,每个我的负载均衡的情景Web服务器将轮询该键的值和刷新缓存的变化。这将是一个非常糟糕的机制,我刷新缓存中的项目,每天一次在最大。我也无法实现与使用服务代理通知的的SqlCacheDependency因为我有一个MySQL数据库推送通知。有什么想法吗?是否有任何肮脏的工作,身边?一个可能的解决方法,暴露一个aspx页面,并使用在该网站托管,而不是域名的IP地址和端口打的页面多次 - 例如: HTTP://ip.ip.ip.ip:82 / CacheClear.aspx ,以便为该页面的请求可能会发送到所有的工作进程该网站服务器内,并在Page_Load中,清除缓存项。但是,这是一个非常肮脏的黑客当所有请求都发送到相同的工作进程的情况下可能无法正常工作。

I have an asp.net web application running on IIS 7 set-up in web-garden mode. I want to clear runtime cache items across all worker processes using a single-step. I can setup a database key-value, but that would mean a thread executing on each worker process, on each of my load-balanced-scenario web servers will poll for changes on that key-value and flush cache. That would be a very bad mechanism as I flush cache items once per day at max. Also I cannot implement a push notification using the SqlCacheDependency with Service Broker notifications as I have a MySql db. Any thoughts? Is there any dirty work-around? One possible workaround, expose an aspx page, and hit that page multiple times using the ip and port on which the site is hosted instead of the domain name - ex: http://ip.ip.ip.ip:82/CacheClear.aspx, so that a request for that page might be sent to all the worker processes within that webserver, and on Page_Load, clear the cache items. But this is a really dirty hack and may not work in cases when all requests are sent to the same worker process.

推荐答案

您需要设置进程间通信。
对于高速缓存有这样的两种常用的方法:

You need to setup inter-process communication. For caching there are two commonly used ways of doing this:


  • 设置一个共享的缓存(memcached的等等。)

  • 设置一个消息队列(例如MS-mqueue中或RabbitMQ的),并用它为s $ P $垫状态到本地缓存。

一个共享缓存是最终的解决方案,因为它意味着整个缓存分发,但它也是最复杂的:它需要进行设置,以便缓存负载分布适当节点之间,并确保它不会成为一瓶颈。

A shared cache is the ultimate solution as it means the whole cache is distributed but it is also the most complex: it needs to be set up so the cache load is properly distributed between nodes and make sure it doesn't become a bottle neck.

第二个选项需要你更多的code,但它更容易,如果你不希望共享的缓存内容(如你的情况)。
最简单的是先建立一个监听线程或任务来处理缓存清除或单个条目无效的消息。如果没有消息,因此对性能的影响是最小的这个线程将处于休眠状态。
您也可以通过处理消息作为一般的IIS请求管道的一部分,放弃监听线程。即设置一个过滤器/模块,检查队列中的消息和处理请求之前对其进行处理;但性能明智的第一个选项是(略)更好。

The second option requires more code on your part but it is easier if you don't want to share the cache content (as in your case.) The easiest is to setup a listener thread or task to handle the cache clear or individual entries invalidation messages. This thread will be dormant if there are no messages so the impact on performance is minimal. You can also forgo the listener thread by handling messages as part of the usual iis request pipeline. I.e. set up a filter/module that checks for messages in the queue and processes them before handling the request; but performance wise the first option is (slightly) better.

这篇关于同花顺HttpRuntime.Cache跨越上IIS web服务器的所有工作进程对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆