Sharing an HttpRuntime.Cache across two IIS applications

做~自己de王妃 提交于 2020-01-03 17:47:08

问题


I have two ASP.NET 2.0 applications in IIS; a public booking system and an admin system to manage prices. There is a shared DLL project that accesses the database, used by both applications.

To improve performance, the prices are cached in DLL code to save hitting the database on every request. However, when the administrator changes the prices, the cache is refreshed on the admin application (and obviously it isn't refreshed on the public application)

So, to the question. Is it possible to configure IIS so that these two applications share the HttpRuntime.Cache? If so, how should it be set up?


回答1:


That would beat the point of having two applications - they should not share the same DLL memory heap, that would be needed. What you need is a communications channel between the two and have the admin web-pages notify about changes to the cache - which would cause a refresh.

May be something simple, but maybe a simple page you post to that causes the cache to check for updates? Or - have the application check for updates now and again based on a time stamp.

(Another option is to create a service where the cache resides, but I think that is outside the scope of a simple solution)




回答2:


No; by experience this will not work (.NET 4.6, IIS 8.5, 2 applications a common DLL using the same application pool). Documentation is very hard to come by (beyond "cache items are stored in memory") - in fact the only descriptive part was what @Thies stated above - but as he stated I believe this is because the cache is stored in the DLL's allocated memory, therefore (since we still have one process but two app domains) the common DLL is loaded separately into two application domains and the DLL's memory is not shared.



来源:https://stackoverflow.com/questions/1244105/sharing-an-httpruntime-cache-across-two-iis-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!