I'm stuck trying to figure out why the outputCache is not getting cleared on the following setup.
Pretty much every link I have checked to clear an outputCacheItem says to just call the RemoveOutputCacheItem(string) method. However I am finding that this is not the case. I get the method once in the debugger, it goes to the ClearCacheName(), Runs the removal. After that I never hit the method again, telling me the cache is stuck and consequently the resultset is null forever.
[OutputCache(Duration = int.MaxValue, Location = OutputCacheLocation.Server)]
public JsonResult GetNames()
{
if (SomeResultSet != null)
{
var results =
SomeResultSet
.Where(x => x.LookupName != null)
.OrderBy(x => x.LookupName)
.Select(x => new
{
value = x.LookupName,
label = x.LookupName
}).Distinct();
return new JsonResult() {Data = results, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
}
ClearCacheNames();
return null;
}
private void ClearCacheNames()
{
// OutputCacheAttribute.ChildActionCache = new MemoryCache(new Guid().ToString());
Response.RemoveOutputCacheItem(Url.Action("GetNames","Search",null));
}