I have an ASP.NET (vb.net rather than c#) website with a large number of individual pages. To cut down on duplicated code, I have the site’s main template as a master page.
There is a particular variable (let’s call it Sale) which is used in every single page AND the master page.
At the moment, I’ve got a simple SQL query in every page AND in the master page that runs each time the page is loaded to check what the value of Sale is (either a 1 or a 0) and, depending on that value different sections of code display.
My problem is that this seems (to me) like a lot of redundant/duplicate SQL calls.
I could write the value of Sale to a session variable, but for a whole bunch of reasons this isn’t really practical, so what other options are open to me?
asp.net provides a very good caching mechanism. This will allow you to cache any objects you want.
This topic is rather vast, so I will only give you a few pointers:
Caching Application Data
Adding items to cache
Since you are looking to optimize your queries look at SqlCacheDependency.