简体   繁体   English

在ASP.NET中的两个Web应用程序之间共享数据

[英]Sharing Data Between Two Web Applications in ASP.NET

I have a web application (MainApplication) where many of the pages contain a custom Web Control that looks for some content in a cache. 我有一个Web应用程序(MainApplication),其中许多页面包含一个自定义Web控件,该控件在缓存中查找某些内容。 If it can't find any data within the cache, then it goes out to a database for the content. 如果在缓存中找不到任何数据,则将其发送到数据库以获取内容。 After retrieving the content, the Control displays the content on the page. 检索内容后,控件将在页面上显示内容。

There is a web application (CMS) in a subdirectory within the aforementioned web application. 在上述Web应用程序的子目录中有一个Web应用程序(CMS)。 Users use this CMS to update the content pulled in by the MainApplication. 用户使用此CMS更新MainApplication提取的内容。

When a user updates some content using the CMS, I need the CMS to clear the relevant portion of the cache used by the MainApplication. 当用户使用CMS更新某些内容时,我需要CMS清除MainApplication使用的缓存的相关部分。 The problem is that, as two different web applications, they can't simply interact with the same static cache object. 问题在于,作为两个不同的Web应用程序,它们不能简单地与同一个静态缓存对象进行交互。

The ideal solution would be to somehow share an instance of a cache object between both web applications. 理想的解决方案是在两个Web应用程序之间以某种方式共享缓存对象的实例。

Failing that, what would be the best (performance-wise) way of communicating between the two web applications? 如果不这样做,两个Web应用程序之间最好的(性能方面)通信方式是什么? Obviously, writing/reading to a database would defeat the purpose. 显然,对数据库进行写入/读取将无法达到目的。 I was thinking about a flat file? 我在考虑平面文件吗?

Update 更新资料

Thank you all for your help. 谢谢大家的帮助。 Your wonderful answers actually gave me the right search terms to discover that this was a duplicate question (sorry!): Cache invalidation between two web applications 您的精彩回答实际上为我提供了正确的搜索词,以发现这是一个重复的问题(对不起!): 两个Web应用程序之间的缓存无效

One option that comes to my mind in such scenario is using Velocity distributed cache mechanism. 在这种情况下,我想到的一个选择是使用Velocity分布式缓存机制。 Do read about it and give it a try if possible http://msdn.microsoft.com/en-us/magazine/dd861287.aspx 请仔细阅读并尝试一下, http://msdn.microsoft.com/zh-cn/magazine/dd861287.aspx

We had the exact same setup in a previous project i worked on, where we had one ASP.NET Web Application (with MCMS Backing), and another ASP.NET Web Application to display data. 我们在以前的项目中进行了完全相同的设置,在该项目中,我们有一个ASP.NET Web应用程序(带有MCMS支持)和另一个ASP.NET Web应用程序来显示数据。

Completely different servers (same domain though). 完全不同的服务器(虽然相同的域)。

However, when a "editor" updated content in the CMS application, the UI was automatically refreshed. 但是,当“编辑者”更新CMS应用程序中的内容时,UI会自动刷新。

How? 怎么样? Glad you asked. 很高兴你问。

We stored the content in SQL Server, and used Replication. 我们将内容存储在SQL Server中,并使用了复制。 :) :)

The "frontend" Web Application would read the data from the database (which was replicated by the CMS system). “前端” Web应用程序将从数据库中读取数据(由CMS系统复制)。

Now - we don't cache this data, because in the database, we actually stored the markup (the HTML) for the control. 现在-我们不缓存这些数据,因为实际上在数据库中,我们存储了控件的标记(HTML)。 Therefore we dynamically re-rendered the HTML. 因此,我们动态地重新渲染了HTML。

Why is that "defeating the purpose"? 为什么那是“违背目的”?

You can't get one application to "invalidate" the cache on another application. 您无法让一个应用程序“无效”另一应用程序上的缓存。

If you're going down this path, you need to consider a distributed caching engine (eg Velocity). 如果您走这条路,则需要考虑一个分布式缓存引擎(例如Velocity)。

In ASP.NET there is the notion of Cache Dependency. 在ASP.NET中,有“缓存依赖项”的概念。 You can have a look here: http://www.codeproject.com/KB/web-cache/CachingDependencies.aspx or http://www.devx.com/dotnet/Article/27865/0/page/5 . 您可以在这里查看: http : //www.codeproject.com/KB/web-cache/CachingDependencies.aspxhttp://www.devx.com/dotnet/Article/27865/0/page/5

There is also the Enterprise Library Caching Block available here that adds some feature to the standard stuff: http://msdn.microsoft.com/en-us/library/ff649093.aspx 这里还有可用的企业库缓存块,为标准内容添加了一些功能: http : //msdn.microsoft.com/zh-cn/library/ff649093.aspx

Now, if you're running on .NET 4, there is a new System.Runtime.Caching namespace that you should definitely use: http://msdn.microsoft.com/en-us/library/system.runtime.caching.aspx 现在,如果您在.NET 4上运行, 肯定要使用一个新的System.Runtime.Caching命名空间: http : //msdn.microsoft.com/zh-cn/library/system.runtime.caching。 aspx

This article here "Caching in ASP.NET with the SqlCacheDependency Class" is quite interesting: http://msdn.microsoft.com/en-us/library/ms178604.aspx 这篇文章“使用SqlCacheDependency类在ASP.NET中进行缓存”非常有趣: http : //msdn.microsoft.com/zh-cn/library/ms178604.aspx

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

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