0

I have any experiences with caching of the data in the Asp.Net Webforms applications.

I have the web farm with the four servers.

I have a table with the constants in MSSQL Server.

I don't want to select these constants with every http request from DB, but ideally save the values into the cache and getting these values from the cache.

How can I do this on the web farm? What is the best way for do this?

Jenan
  • 3,408
  • 13
  • 62
  • 105

2 Answers2

1

You can use HttpContext.Cache to store these values, with a long expiry time, or if they are really constant (i.e. they absolutely NEVER change) then you can use a static class with static readonly properties and fill those properties once from the database.

In both cases they can be used all over the application. This approach when used in a web farm does mean that every server will retrieve the values once, instead of once for the whole farm, but unless the number of values goes into the 10,000's I personally wouldn't worry about that.

Peter B
  • 22,460
  • 5
  • 32
  • 69
-1

If the data will truly never change you could also use HttpContext.Current.Application to store the information.

According to an overview here:

Application is not a cache, its a global named value collection. if you add an object to Application it will stay until a an appdomain recycle.

  • Application variables are shared variables among all users of a web application
  • Application variables behave like static variables and they are substitute of static variables as static variables are stateless in web applications
  • Only shared values should be persisted in Application variables, and as soon as they are not in use they should be removed explicitly.

Cache :It is possible to obtain significant performance improvements in ASP.NET applications by caching frequently requested objects and data in either the Application or Cache classes. While the Cache class certainly offers far more flexibility and control, it only appears to offer a marginal advantage in terms of increased throughput over the Application class for caching. It would be very difficult to develop a testing scheme that could accurately measure the potential advantages of the Cache class's built - in management of lesser-used objects through the scavenging process as opposed to the fact that Application does not offer this feature. The developer needs to take decision in this case and should be based on the needs and convenience of the project and its usage patterns.

Community
  • 1
  • 1
denpone
  • 1
  • 3
  • 1
    Welcome to Stack Overflow! While the link may answer the question, links change, so Stack Overflow prefers to not depend on them. [It would be better](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here and provide the link for reference. – Dave Schweisguth Mar 31 '16 at 20:14