I have setup a cache profile in my asp.net core web api as follows:
services.AddMvc(options => {
// Cache profile for lookup data will expire every 15 minutes.
options.CacheProfiles.Add("LookupData", new CacheProfile() { Duration = 15 });
});
I have used this attribute at the top of my "lookupsController", as the lists of information returned in each method won't change regularly (although cache automatically expires every 15 minutes).
[ResponseCache(CacheProfileName = "LookupData")]
[Produces("application/json")]
[Route("api/Lookups")]
public class LookupsController : Controller
{
...
}
I have another admin controller which can allow users to add and remove items in the lookups controller list, this won't happen often but when it does, I want to programmatically force the cache profile to reset and force subsequent web requests to get the latest, rather than keeping the now outdated cached list of data.
How do I achieve the resetting of cache programmatically? - I can then add this code into my admin controller methods, to force cache resetting. Has anyone had to do this before?