简体   繁体   English

ASP.NET缓存管理

[英]ASP.NET Cache Management

I have three applications running in three separate app pools. 我有三个应用程序在三个独立的应用程序池中运行 One of the applications is an administrative app that few people have privileged access to. 其中一个应用程序是一个很少有人有权访问的管理应用程序。 One of the function the administrative app allows is creating downtime notices. 管理应用程序允许的功能之一是创建停机通知。 So when a user goes into the administrative app and creates a downtime notice the other two apps are supposed to pick up on there being a new notice and display it on the login page. 因此,当用户进入管理应用程序并创建停机通知时,其他两个应用程序应该接收新通知并将其显示在登录页面上。

The problem is that these notices are cached and being that each app is in a separate app pool the administrative app doesn't have any way to clear the downtime notices cache in the other two applications. 问题是这些通知被缓存,并且每个应用程序都在一个单独的应用程序池中,管理应用程序无法清除其他两个应用程序中的停机通知缓存。

I'm trying to figure out a way around this. 我正试图想办法解决这个问题。 The only thing I can think of is to insert a record in the DB that denotes the cache needs to be cleared and the other two apps will check the DB when loading the login page. 我唯一能想到的是在DB中插入一条记录,表示需要清除缓存,其他两个应用程序将在加载登录页面时检查数据库。 Does anyone have another approach that might work a little cleaner? 有没有人有另一种可能更清洁的方法?

*Side note, this is more widespread than just the downtime notices, but I just used this as an example. *旁注,这比停机通知更广泛,但我只是以此为例。

EDIT 编辑

Restarting the app pools is not feasible as it will most likely kill background threads. 重新启动应用程序池是不可行的,因为它很可能会杀死后台线程。

If I understand correctly, you're basically trying to send a message from the administrative app to other apps. 如果我理解正确,您基本上是尝试从管理应用程序向其他应用程序发送消息。 Maybe you should consider creating WCF service on these apps that could be called from the administrative application. 也许您应该考虑在可以从管理应用程序调用的这些应用程序上创建WCF服务。 That is a standard way to communicate between different apps if you don't want to use eg shared medium such a database and it doesn't force you to use polling model. 如果您不想使用例如共享介质这样的数据库并且它不会强制您使用轮询模型,那么这是在不同应用程序之间进行通信的标准方法。

Another way to look at this is that this is basically an inter-application messaging problem, which has a number of libraries already out there that could help you solve it. 另一种看待这种情况的方法是,这基本上是一个应用程序间消息传递问题,其中有许多库已经可以帮助您解决它。 RabbitMQ comes to mind for this. RabbitMQ就是为此而想到的。 It has a C# client all ready to go. 它有一个C#客户端都准备好了。 MSMQ is another potential technology, and one that already comes with Windows - you just need to install it. MSMQ是另一种潜在的技术,也是Windows附带的技术 - 您只需安装它即可。

If it's database information you're caching, you might try your luck at setting up and SqlCacheDependency . 如果您正在缓存数据库信息,那么您可以尝试设置和SqlCacheDependency

Otherwise, I would recommend not using the ASP.NET cache, and either find a 3rd party solution that uses a distributed caching scheme, that way all applications are using one cache, instead of 3 separate ones. 否则,我建议不要使用ASP.NET缓存,并找到使用分布式缓存方案的第三方解决方案,这样所有应用程序都使用一个缓存,而不是3个独立缓存。

I'm not saying this is the best answer or even the right answer, its just what I did. 我不是说这是最好的答案,甚至是正确的答案,这正是我所做的。

I have a series of ecommerce websites on separate servers and data centers that rely on pulling catalog data from a central backoffice website location and then caches them locally. 我在单独的服务器和数据中心上有一系列电子商务网站,它们依赖于从中央后台网站位置提取目录数据,然后在本地缓存它们。 In my first iteration of this I simply used GET requests that the central location could ping the corresponding consuming website to initiate its own cache refresh routine. 在我的第一次迭代中,我只使用了GET请求,中心位置可以ping相应的消费网站以启动自己的缓存刷新例程。 I used SSL on each of the eCommerce servers as I already had that setup and could then have the backoffice web app send credentials via SSL GET to initiate the refresh securely. 我在每个电子商务服务器上都使用了SSL,因为我已经进行了设置,然后可以让后台Web应用程序通过SSL GET发送凭据以安全地启动刷新。

At a later stage, we found it more efficient to use sockets instead on the backoffice where each consuming website would be a client and listen for changes in the data. 在稍后阶段,我们发现在后台使用套接字更有效,每个消费网站都是客户端并监听数据的变化。 The backoffice website could then communicate to its corresponding website when a particular account change and then communicate this very specifically. 然后,当特定帐户发生变化时,后台网站可以与其相应的网站进行通信,然后非常具体地进行通信。 This approach is much more granular and we could update in small bits as needed as opposed to a large chunked update but this was definitely more complicated than our first try. 这种方法更精细,我们可以根据需要更新小块,而不是大块更新,但这肯定比我们的第一次尝试更复杂。

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

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