Caching http handler .ashx output

前端 未结 2 520
广开言路
广开言路 2021-02-10 19:33

Im creating an image which has some text in it, for every customer, the image contains their name and I use the Graphics.DrawString function to create this on the fly, however I

2条回答
  •  被撕碎了的回忆
    2021-02-10 20:11

    David,

    you can use output caching on handler. not declaratively but in code behind. see if you can use following snippet.

    TimeSpan refresh = new TimeSpan(0, 0, 15);
    HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.Add(refresh));
    HttpContext.Current.Response.Cache.SetMaxAge(refresh);
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Server);
    HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
    
    //try out with – a simple handler which returns the current time
    
    HttpContext.Current.Response.ContentType = "text/plain";
    HttpContext.Current.Response.Write("Hello World " + DateTime.Now.ToString("HH:mm:ss"));
    

提交回复
热议问题