Sharing an HttpRuntime.Cache across two IIS applications
Asked Answered
P

2

4

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?

Puke answered 7/8, 2009 at 10:49 Comment(0)
F
3

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)

Floro answered 7/8, 2009 at 10:53 Comment(1)
Thanks Thies. That's what I suspected. I have already added a generic handler to the public site that is called by the admin site, but I was wondering if there was a neater way.Puke
H
0

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.

Hypnotist answered 13/1, 2016 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.