0

I'm working with ASP.NET and I want to load once a big object (specific by user) in my controller and then use it in my view. I though about a static property but I find some problems with it. See : Is it a bad idea to use a large static variable?

I'm not familiar with this language and I have no idea how to properly share the same object between the different methods for each user. Could you tell me how to do that ? Do you know if singleton could be a solution ?

1
  • Do you know what a singleton is? And when/why you should apply it? Commented Jan 29, 2014 at 14:42

2 Answers 2

1

A singleton won't help you here if this big object is going to be different for every user.

Without knowing all the details, I'd say perhaps your best option is to store it in the Session object,

HttpContext.Current.Session["bigObject"] = bigObject;

Depending on the size & traffic, this can have performance problems, so I'd suggest you read up on the pros and cons of using Session

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

Comments

0

If you want to get to use something for the next simultaneous request, then use TempData - which is a bucket where you can hold data that is only needed for the following request. That is, anything you put into TempData is discarded after the next request completes.

If you want to persist the information specific to user, then go for Session. With session, you will have timeout, so that after certain amount of time the data stored in session will be lost. You can configure this value to much more bigger value. Apart from that when you go for Webfarm of servers, then maintaining session will be a problem, probably you might need to go for managing session in SQL Server or in some other store.

Alternatively you can Use Runtime Cache object in ASP.Net MVC to keep all the common data. Cached data can be accessed fast and we have other benefits like expiring cache etc. You can share this Cache object across users, or you can maintain different cache objects for different users, that is purely dependent on your logic. In case of webfarms, yo u have distributed cache servers like redis, Azure Cache service etc., which you can use them.

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.