I am working on a search page containing several drop-down lists with different database values. I started learning caching techniques and came up with several possible solutions.
- OutputCaching
- HttpContext.Cache
Since I read more about the different types of caching, I remembered that this application also provides metric pages that can use the same drop-down menus from the search page. Now, instead of a search page solution, I want a solution for the entire site.
The method of obtaining individual values ββin both cases is almost identical. I have a ViewModel with various "Available" fields. These fields are filled in the constructor.
public class SearchViewModel { public AvailableSites {set;get;} public SearchViewModel() { AvailableSites = db.SomeTable.Select(s => s.Site).Distinct(); } }
When my model is set up this way, every time the user clicks on the search or metrics page, the application must go to the database to populate the drop-down menus. Caching will significantly reduce the load it puts on db and the network.
It seems that OutputCache only works with controller actions, so this is out of the question.
The result of a single query will change very rarely. Is this something I want to cache using an HttpContext? What type of caching will work best in this case?
Also, what would be the best way to integrate this into my MetricBase (each metric VM inherits from this) and SearchViewModel? Inheritance is almost like an unnecessary situation for this situation. I would simply include the private AvailableValue Values {set;get;}
class as such and access them through Values.AvailableSites
?
source share