简体   繁体   English

如何从同一服务器上的另一个asp.net应用程序清除asp.net应用程序的缓存?

[英]How to clear the cache of an asp.net application from another asp.net application on the same server?

Got a bit of an odd problem. 有一个奇怪的问题。 Here goes: 开始:

I have two ASP.NET applications: A web app and a web service app. 我有两个ASP.NET应用程序:一个Web应用程序和一个Web服务应用程序。

Information arriving via the webservice effects data in the database used by the web app. 通过网络服务到达的信息会影响网络应用所使用的数据库中的数据。

One particular bit of data controls items in a drop down menu - when the data is altered in the app it can call: 数据的一个特定位控制下拉菜单中的项-当应用中的数据发生更改时,它可以调用:

HttpContext.Current.Cache.Remove

but I now need to clear the cache in the web service as i can recieve messages which update that information. 但是我现在需要清除Web服务中的缓存,因为我可以接收更新该信息的消息。

Can anyone recommend a way of doing this? 有人可以推荐这样做的方法吗?

Cache invalidation can be hard. 缓存失效可能很难。 Off the top of my head I can think of 3 solutions of varying complexity which may or may not work for you. 我不由自主地想到了3种复杂程度不同的解决方案,这些解决方案可能对您不起作用。

First, you could write a web service for the web app that the web service app calls to invalidate the cache. 首先,您可以为该Web应用程序编写Web服务,该Web服务应用程序调用该Web服务以使缓存无效。 This is probably the hardest. 这可能是最难的。

Second, you could have the web service app write a "dirty" flag in the database that the web app could check before it renders the drop down menu. 其次,您可以让Web服务应用程序在数据库中写入一个“脏”标志,Web应用程序可以在呈现下拉菜单之前对其进行检查。 This is the route I would go. 这是我要走的路。

Third, you could simply stop caching that particular data. 第三,您可以简单地停止缓存该特定数据。

You could have a web method whose sole purpose is to clear the cache. 您可能有一个Web方法,其唯一目的是清除缓存。

var webRequest = HttpWebRequest.Create(clearCacheURL);
var webResponse = webRequest.GetResponse();

// receive the response and return it as function result
var sr = new System.IO.StreamReader(webResponse.GetResponseStream());
var result = sr.ReadToEnd();

Implement the cache with an expiry time. 实现具有过期时间的缓存。

Cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration); Cache.Insert(“ DSN”,connectionString,null,DateTime.Now.AddMinutes(2),Cache.NoSlidingExpiration);

Cache.Insert Method Cache.Insert方法

You can try SQL Dependency. 您可以尝试SQL依赖关系。 It will trigger an event when the table you have subscribed has any changes. 您预订的表有任何更改时,它将触发一个事件。

https://www.codeproject.com/Articles/12335/Using-SqlDependency-for-data-change-events https://www.codeproject.com/Articles/12335/Using-SqlDependency-for-data-change-events

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

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