sql-servercachingwebformsweb-farm

How to use the cache for store constants from DB in Asp.Net WebForms on the web farm?


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?


Solution

  • 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.