Reputation: 24052
So when a user comes to my page, there is certain data that I want to store from how they are interacting with the page. None of this data is being persisted though, so I'm trying to figure out the best way to do it.
For example, they log onto my page, and I'm getting their location through javascript/google maps. Should I store that in the session? I'm also getting their IP through javascript. Should I just make the javascript query everytime I need to use it or should I store that in the session as well?
Is cacheing better than storing things in the session? Should I put this all in a model
, put the model
in the cache, and then use a Guid
to retirve the right model
for the right user in the cache? Would this get crazy expensive if thousands of users were on the page at once?
Users are also able to get a list of records from the database using this information that I'm gathering as params to a stored proc. This list sometimes needs to be re-queried for, but other times, it just needs to be re-sorted on the page. I wouldn't want to query for all of these everytime I'm just sorting through it, but would the cache be able to hold like thousands of records in it for each user logged in?
I've just never came across this stuff in MVC before so I could use a little guidance.
Thanks guys.
Upvotes: 0
Views: 562
Reputation: 6931
If you want to persist some user data through the course of the user's visit, you can use the ASP.NET session, cookies or some other more permanent persistence medium such as a database. I typically store user data as objects that are serialized to json, encrypted and written out to a cookie. This allows me to persist the data across multiple visits, even if they leave and come back.
As far as caching data, there are many choices and ASP.NET has some nice built in features to make it easier for you. When you cache data it will be store in the memory on your web server, unless you setup an external caching server such as memcached. The cached data can be shared between multiple users if it is common data, to eliminate wasteful caching. You can also set up caching invalidation so the cache gets automatically cleared if the data becomes old.
As far as amount of data to cache, that will depend on what you're caching, how large those objects are in memory, how many users will be creating these cached objects, and how much memory your server has available.
Ideally you would want to calculate it out to determine what the cost will be.
Upvotes: 2