0

enter image description here

I am using Sql server to upload images and the uploaded images are immediately reflected in the grid below.my problem is when ever i change or edit the picture,the picture is changed in the database but the grid shows the previous image that I had deleted.and i have to log out and lo-gin again to see the changes. Is there any way to over come this? Is there any way to clear cache each time the grid reloads?

Community
  • 1
  • 1
AfterGlow
  • 227
  • 3
  • 17

3 Answers3

0

You can try writing your own attribute such as [no-cache] in the post below, and can use it on your controller to prevent caching.

Prevent Caching in ASP.NET MVC for specific actions using an attribute

http://dotnetnsqlcorner.blogspot.co.uk/2012/09/disable-caching-for-controller-action.html?m=1

To disable client side caching, you could also use [outputcacheattattribute] on your action result. Below post might help.

[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] 

How can I disable client side and proxy caching in ASP.NET MVC?

There are other ways of disabling the cache as well,, but I guess one of the above two approaches should do the job. Hope this helps

Community
  • 1
  • 1
Ren
  • 1,493
  • 6
  • 31
  • 56
0

You can use the Duration for particular catche into your project:

just have a look to this: http://dotnet.dzone.com/articles/programmatically-clearing-0

and If cache is formed on Client-side using Jquery-ajax then use::

$.ajax({
    cache: false
    //rest of your ajax setup
});
Rahul
  • 2,309
  • 6
  • 33
  • 60
0

You can target your action methods and create a no cache action filter attribute in addition to cache: false in your ajax call.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class NoCacheAttribute : 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);
  }
}

This is well explained Here. Hope it helps.

Community
  • 1
  • 1
Rohit416
  • 3,416
  • 3
  • 24
  • 41