0

I am trying to have a variable that is an object exist once on the server for an ASP.Net Application. I want to fire it up and then allow every user of the application to have it.

My understanding is that the Global.asax file contains a method called Application_Start that starts up every time a user calls for the first time. And it has a method Application_BeginRequest for each request. The method Application_Start does not suit my needs as it is once per user.

Is it possible to somehow have an object for all users?

Storing a global variable in a static class will not work either as it once instance per user of the application.

The reason for the need is we are trying to use a new product and improve performance(speed) and the declaration and initialization of this object is a performance cost we are trying to circumvent.

Stackoverflow-Global.asax does not really help me and

Stackoverflow-SessionVariables does not solve my need

Is there a way of storing an object variable in a file available for the whole pool of users? I am at a a loss as tho the solution?

Darren
  • 1,352
  • 5
  • 19
  • 49
  • Why not use `MemoryCache`? – JohanP Jan 23 '19 at 03:09
  • @JohanP I had not heard of MemoryCache until you mentioned it and I am looking into it. Can I store object there and access them from my ASP.Net application? – Darren Jan 23 '19 at 03:14
  • I think it is just called `Cache` in asp.net webforms. It will sit in memory on the server. If you have a web farm setup, then each machine will have to create the heavy object. – JohanP Jan 23 '19 at 03:16
  • @JohanP Cache seems like it would suit our needs. We will give it a go. – Darren Jan 23 '19 at 03:31
  • @JohanP Thanks for that. I am getting really good speeds for retrieving the object from Cache. Do you want to post that as an answer as I will accept it? – Darren Jan 23 '19 at 04:29

1 Answers1

1

You can use Cache to cache you application data machine wide.

JohanP
  • 5,252
  • 2
  • 24
  • 34