views:

338

answers:

7

I am currently working on a large-scale website, that is very dynamic, and so needs to store a large volume of information in memory on a near-permanent basis (things like configuration settings for the checkout, or the tree used to implement the menu structure).

This information is not session-specific, it is consistent for every thread using the website.

What is the best way to hold this data globally within ASP, so it can be accessed when needed, instead of re-loaded on each use?

+1  A: 

Any AppSettings in web.config are automatically cached (i.e., they aren't read from the XML every time you need to use them).

You could also manually manipulate the cache yourself.

Edit: Better links...

John Rasch
AppSettings is not really suitable, as far as I am aware, I'm talking about storing things like collections of products -> actual objects.
Ed Woodcock
Then you'll likely want the second half of my answer
John Rasch
+1 for caching feature.
Canavar
Could whoever downvoted this explain why it would be a bad idea to use the cache?
John Rasch
Decided to go with the Application Cache, seems to do the trick!
Ed Woodcock
+1  A: 

It's not precisely clear whether your information is session specific or not...if it is, then use the ASP Session object. Given your description of the scale, you probably want to look at storing the state in Sql Server:

http://support.microsoft.com/kb/317604

That's the 101 approach. If you're looking for something a little beefier, then check out memcached (that's pronounced Mem-Cache-Dee):

http://www.danga.com/memcached/

That's the system that apps like Facebook and Twitter use.

Good luck!

Chris B. Behrens
A: 

I usually keep things like that in the Application object.

Dave Ward
Could you possibly exapnd on that answer, perhaps some short example code or a link to a decent tutorial?
Ed Woodcock
+1  A: 

Using ASP.NET caching feature is a good option I think. In addition to John's answer, you can use Microsoft's Patterns & Practices team's Caching Application Block.

Canavar
A: 

If the pages are dependent upon one another and they post to one another, you could use the page's request object. Probably not the answer you're looking for, but definitely one of the smallest in memory to use.

MattK311
+1  A: 

This is a good video exploring the different ways to can retain application state. http://www.asp.net/learn/3.5-videos/video-11.aspx It brushes on the Application object which is global for the whole application, for all users and shows you how to create a hit counter (obviously instead of storing an integer you could store objects). If you need to make changes, you do need to use a lock for concurrency, and I'm not sure how it handles LARGE amounts of data because I've never had to keep that much there.

Chet
A: 

I have run into the same situation in the past and found an interface to be the most scalable solution. Application cache may be the answer today, but will it scale to meet your needs?

If you need to scale up, you may find cookies, or some type of temp database storage to be the trick. Simply add a new method to your interface, and set the interface to choose the "mode" from web.config.

lacourem