0

I have IHttp Generic Handler (.ashx) for images and I have sent cache expire time as 7 days but in Google page insight it says I should add cache validator. following is my code. Please refer me something.

    public void ProcessRequest(HttpContext context)
    {
        TimeSpan refresh = TimeSpan.FromDays(7);
        context.Response.Cache.SetExpires(DateTime.Now.Add(refresh));
        context.Response.Cache.SetMaxAge(refresh);
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.CacheControl = HttpCacheability.Public.ToString();
        context.Response.Cache.SetValidUntilExpires(true);
    }

Thanks

aadi1295
  • 982
  • 3
  • 19
  • 47

1 Answers1

0

After some research I found out that we can add Etag or SetLastModified or just Add a header into cache like below:

context.Response.Cache.SetETag(DateTime.Now.ToLongDateString());
context.Response.Cache.SetLastModified(DateTime.Now.ToLongDateString());
context.Response.AddHeader("Last-Modified", DateTime.Now.ToLongDateString());
aadi1295
  • 982
  • 3
  • 19
  • 47