Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am using OutputCache to cache for duration like 60 sec on ActionMethod that retrun the list of item. It work fine, but the problem is when i add item in list then the ActionMethod return the previous list, the new item not shown in list for 60 sec. How i can overcome this problem?
Posted
Comments
SwarupDChavan 15-Apr-14 7:41am    
Hey you can try to create a clear cache actionfilter and then decorate the specified Action(the one that adds item to the list) in the controller with the action name and once done you can fill the list again to be cached the actionfilter would be something like given below.
[no name] 20-Apr-14 1:52am    
you can dynamically clear the cache. But if your requirement is as such then either reduce the time duration for output cache else use Donut Caching..
Thanks
Vi(ky 21-Apr-14 8:01am    
Thank you

1 solution

C#
public class ClearCache : ActionFilterAttribute
{
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
        filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        filterContext.HttpContext.Response.Cache.SetNoStore();

        base.OnResultExecuting(filterContext);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900