Refresh OutputCache Profile on Demand

天涯浪子 提交于 2021-01-29 15:20:30

问题


I am using an OutputCache Profile to cache on the server some json data.

    [HttpGet]
    [OutputCache(CacheProfile = "1HourCacheProfile")]
    public JsonResult GetBranches()
    {
        var result = mMapper.Map<List<IntItem>>(mConfigurationServices.GetBranches());
        return Json(new { list = result }, JsonRequestBehavior.AllowGet);
    }

The profile is registered in Web.config as below

I want to hook somehow a refresh logic on this cached output on different actions that are updating my source. I have found some solution where I can remove an action from the cache with something like below, but I was wondering if there is a way to use some type of filter to refresh all the cached items of my profile.

//  Get the url for the action method:
var staleItem = Url.Action("Action", "YourController", new
{
    Id = model.Id,
    area = "areaname";
});

//  Remove the item from cache
Response.RemoveOutputCacheItem(staleItem);

来源:https://stackoverflow.com/questions/64976253/refresh-outputcache-profile-on-demand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!