Reputation: 4063
I'm using asp.net mvc3. Our app heavily uses the HttpRuntime.Cache to store data in memory on the web server to reduce database calls.
My issue is that every time I run the app locally (F5 in Visual Studio) the cache appears to be cleared, causing a full reload of all the data from the database. i.e. I run once, get the data from the db then stop. If I run again seconds later the cache appears to have been invalidated and the database call happens again. My timeouts are all way in the future so not sure what's going on here.
I really only want to get the data when the cache is really empty, not every time I hit F5 in VS. Is there a way to turn off the setting that's clearing my cache every time I run locally?
Thanks!
Upvotes: 1
Views: 856
Reputation: 13266
If you want to retain the cache even after compilation, I would recommend to take the cache outside the process by using other caching frameworks such as AppFabric or memcached. These frameworks use distributed caching which stores the cache out of process and thus avoiding invalidating of cache every time you compile.
Upvotes: 2
Reputation: 93444
Every time you stop debugging, it kills the App Domain, in which the cache is stored. There's nothing you can do about this, because in order to recompile the app, and start the new app, you must build a new AppDomain.
Upvotes: 2
Reputation: 6111
There is no way to prevent this. When you Stop the debugger in VS and then reattach the debugger again it will recycle the Worker Process. Anything cached in the worker process will be flushed out as the process will be started fresh.
Upvotes: 1