Problems Caching dynamic image in the HttpHandler RRS feed

  • Question

  • User-1837983005 posted

    I've got a custom built HttpHandler that I use to display the image blobs from the db. I am getting the image straight from the db, resize it if neccessary, cache it and display on the web page. The problem I am having is that, eventhough the images are being cached in my temp internet folder they are reloaded from the db on each request.

    Actually, when i rebuild the complete solution the images get cached and they are also pulled from the cache on each call. but if i use my web app for few minutes, all of the sudden, i get few images here and there that are not being pulled from the cache. The more I use my web app the more pics quit being loaded from the cache.

    i have no clue what am i doing wrong here... Is this a bug and if so how do I fix it?

    Why are my images being saved to cache, then being pulled from cache and then just simply quit being pulled from cache?


    Images are loaded like this:
    <img border="0" src="image.axd?type=Cat1&amp;id=e7810e9f-2abe-4a54-9b58-d82cd2b8fa6d&amp;width=150" />

    I cache the image like this in the HttpHandler:
    context.Cache.Insert(cacheKey, picInfo);
    new TimeSpan(0, expireInMinutes, 0));

    Then I output the image like this:
    context.Response.ContentType = picInfo.ContentType;
    context.Response.BufferOutput = false;
    context.Response.OutputStream.Write(picInfo.PicBytes, 0, picInfo.PicBytes.Length);

    Monday, August 7, 2006 2:20 PM

All replies

  • User-1837983005 posted
    Tuesday, August 8, 2006 2:34 PM
  • User-1837983005 posted

    anyone have any idea why my dynamic images are first being cached just fine, then after few minutes quit looking for the cached images and reload the dynamic image on each call?

    if someone could at least point me in the right direction i'd be gratefull...


    Thursday, August 10, 2006 12:30 PM
  • User1181216341 posted

    do you have a memory issue on the server?

    I believe cache will be dumped if aspnet doesn't have enough memory to work with?


    Friday, August 11, 2006 10:20 PM
  • User-1837983005 posted

    thanks for replying...

    server's got 2GB of RAM. i am basically trying to get all of the images cached in the client's browser cache so that they are not being loaded from the db on each request for that client. i'd like to cache my dynamic images the same way as the image files are cached in the browser automatically.

    i don't really care if the images are saved in the server's cache. i just want them to cache in the client's browser. how can i accomplish this with the dynamic images?

    i will appreciate any reply.

    thank you

    Monday, August 14, 2006 12:38 PM
  • User-1837983005 posted

    should i re-word the problem? i am still looking for an answer

    Thursday, August 24, 2006 12:10 AM
  • User90671449 posted

    I think you problem is in:


    You should actually get that date from your db and send that back to the browser. Right now you're telling the browser that you've modified the picture just now. The browser response is to get the newly modified version.



    Monday, August 28, 2006 8:32 AM
  • User312496708 posted


    Do you know that in asp.net 2.0 any change in the application folder causes the asp.net engine to restart. This can be one reason why you are facing the problem with cache.

    check this blog to find how the asp.net request are handled and in which event you can use cache.



    Vikram's Blog

    Saturday, September 9, 2006 11:45 PM