Numan
Numan

Reputation: 3948

Store large amounts of data per session ASP.NET MVC

My MVC based application, hooks some web services which send back lots of data! Using the same, I render my views. The web services are slow and out of my control. So I would like to store this info per session, but I am afraid that, this will bring down my web server to its knees. With few hundred users, the web server will run out of memory.

Is there a way that I can store this session data in a file per session? I am more looking at some out of the box open source solutions.

I welcome, new suggestion as well!

Upvotes: 2

Views: 5264

Answers (3)

Caótico fanegas
Caótico fanegas

Reputation: 101

You could just serialize the result collection and save it on files as xml (even process it using linq/XPath directly from XML) , or use any .net native xml database to store and persist data on a file.

Upvotes: 0

Corey
Corey

Reputation: 16584

You can store pretty much any object in the Session storage, with a few exceptions which are generally related to running on a server farm. I'm going to ignore those cases here however.

If you're dealing with only a few MB of data, storing it in the Session object (or a Cache, as @Rick suggests) isn't necessarily a major problem. Once the data has been returned from the web service and parsed into your own internal data structures, simply place the data structure's root object into the Session. I use this method fairly often to store the results of database queries that take a long time to run, especially when the query criteria are unlikely to change frequently.

For larger data sets you should probably use a database to store the information. Create tables that match the structure of the data you're returning and tag the data in some way to indicate how old it is and what criteria were used when fetching it. Update as required, and query the database for records on each client request.

There are plenty of other options, including creating temporary files to store the data using the SessionID to identify them, but I recommend investigating the database option first.

Upvotes: 2

Rick
Rick

Reputation: 3451

Caching is your friend. And since you use MS technology you might want to take a look at the Cache Class

Upvotes: 1

Related Questions