IHttpHandler and Caching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    IHttpHandler and Caching

    Hi,

    Ive got a .ashx file which produces an image (useage: <img
    src="myHandler. ashx" />)

    What do I need to do to make it cache? Every time my page reloads it
    recreates the image (a slow process), and i have a lot of these per page.

    The image-producing code doesn't NEED to be in a handler (in case anyone
    has a better suggestion)

    Thanks


    Andrew
  • Dave Sexton

    #2
    Re: IHttpHandler and Caching

    Hi Andrew,

    In the future you may get better responses if you post ASP.NET questions to
    the microsoft.publi c.dotnet.framew ork.aspnet newsgroup.

    If you're generating the image on-the-fly then you can cache the result
    programmaticall y:

    public Bitmap YourImage
    {
    get
    {
    if (Cache["YourImageK ey"] == null)
    Cache["YourImageK ey"] = GenerateYourIma ge();

    return (Bitmap) Cache["YourImageK ey"];
    }
    }

    "Caching Application Data"


    To allow IIS, proxy servers and the user agent (web browser) to cache the
    request output you can use the following code, for example:

    Response.Cache. SetCacheability (HttpCacheabili ty.Public);

    "How To: Set a Page's Cacheability Programmaticall y"


    --
    Dave Sexton

    "Andrew" <infoREMOVE@THI Smuonlab.comwro te in message
    news:kIlah.2722 5$hK2.12543@new sfe3-win.ntli.net...
    Hi,
    >
    Ive got a .ashx file which produces an image (useage: <img
    src="myHandler. ashx" />)
    >
    What do I need to do to make it cache? Every time my page reloads it
    recreates the image (a slow process), and i have a lot of these per page.
    >
    The image-producing code doesn't NEED to be in a handler (in case anyone
    has a better suggestion)
    >
    Thanks
    >
    >
    Andrew

    Comment

    Working...