1

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!

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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.

1 Comment

This is only true if you have "edit & continue" setting checked (which is the default). If this feature is off in both Cassini and IIS Express the site & app domain will keep running between debugger stop/starts. Many people turn Edit & Continue off for this very reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.