I am writing an MVC webAPI that will be used to return values โโthat will be tied to drop-down lists or used as text results based on text on a website, and I want to cache the values โโin memory, so I donโt have to do database queries when every hit API.
I am going to use the MemoryCache class, and I know that I can fill the cache the first time I log in, but I do not want the first API request to be slower than others. My question is: is there a way to automatically populate the cache the first time I start WebAPI? I see that there is a folder "App_Start", maybe I just drop something here?
After the initial aggregate, I will probably execute the hourly / daily cache update request as needed.
MemoryCache: http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx
UDPATE
Ela's answer below did the trick, basically I just needed to look at the capabilities of Global.asax. Thanks for the quick help here, this raised a separate question for me about the pros / cons of various types of caching.
Pros / cons of various ASP.NET caching settings
vesuvious Sep 21 '13 at 20:55 on 2013-09-21 20:55
source share