0

How can I store data in memory of asp.net mvc application which can be accessed by all users logged in.

Lyubomir Velchev
  • 962
  • 2
  • 11
  • 30
  • that's part of the question - essentially want to store it in RAM, not DB storage. Essentially HttpContext.Current.Application variable that should be common for all users, but not sure if that's the best approach.... – Lyubomir Velchev Jun 05 '15 at 09:49
  • Data will anyways be stored in RAM. – Rahul Jun 05 '15 at 09:50

3 Answers3

1

You can use a static variable. If you have some static Constants class, just create a static list or a static variable.

public static List<string> commonList =  new List<string>
shwetaOnStack
  • 594
  • 4
  • 13
0

You can store the value in your application using something like this:

protected void Application_Start()
{
    HttpContext.Current.Application["somevar"] = "0";
}
cramopy
  • 3,459
  • 6
  • 28
  • 42
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

Something like that will work for me:

Application.Lock();
Application["PageRequestCount"] = 
    ((int)Application["PageRequestCount"])+1;
Application.UnLock();

Here I can save data from user and store it in a data object which will be in application - stored in memory. My idea is to make a chat, but not use a db, relying solely on RAM. So every user will have their messages in their own session, when the user want to submit a message, it will lock and save in messages collection common for all users and the unlock. When the user read - there will be no need for unlocking. Just elaborating about possible use of that, but the answer of the question is the 3 lines source code.

Lyubomir Velchev
  • 962
  • 2
  • 11
  • 30