1

I store a large structure holding my application's reference data in a variable I access through HttpContext.Application. Every once in a while this data needs to change. When I update it in place, is there a danger that incoming requests will see the data in an inconsistent state? Is there a need (and a way) to lock some or all of this structure? Finally, are there other approaches to this problem other than querying the database every time you need this (mostly static) data?

3 Answers 3

1

There are also other solutions availiable, there are many caching providers that you can use.

First of all, there's the HttpRuntime.Cache (which is the same as the HttpContext cache). There's also the System.Runtime.Caching.MemoryCache in .NET 4.

You can set data expiry and other rules for the data in the cache.

http://wiki.asp.net/page.aspx/655/caching-in-aspnet/

http://msdn.microsoft.com/en-us/library/6hbbsfk6.aspx

http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx

More advanced caching includes distributed caches.

Usually, they reside on another server but may also reside on a different process on the same server. Such providers are AppFabric (from Microsoft) and MemCached and others that I can't recall currently.

appfabric: http://msdn.microsoft.com/en-us/magazine/ff714581.aspx

memcached: http://memcached.org/

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

Comments

1

You will not see the application variable in inconsistent state.

The MSDN page for HttpApplicationState says (Under the Thread Safety section):

This type is thread safe.

Comments

0

You may be looking for HttpContext.Items instead to store data in the request scope instead of the application scope. Check out this article to get a great overview of the different context scopes in ASP.NET.

Your solution to avoid querying the database for "mostly static data" is to leverage ASP.NET's caching.

Comments

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.