Problems Caching dynamic image in the HttpHandlerhttp://forums.asp.net/t/1015295.aspx/1?Problems+Caching+dynamic+image+in+the+HttpHandlerSun, 10 Sep 2006 03:45:01 -040010152951363466http://forums.asp.net/p/1015295/1363466.aspx/1?Problems+Caching+dynamic+image+in+the+HttpHandlerProblems Caching dynamic image in the HttpHandler <p>I've got a custom built&nbsp;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. </p> <p>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&nbsp;that are not being pulled from the cache. The more I use my web&nbsp;app the more pics quit being loaded from the cache. </p> <p>i have no clue what am i doing wrong here... Is this a bug and if so how do I fix it? </p> <p>Why are my images being saved to cache, then being pulled from cache and then just simply quit being pulled from cache?</p> <p>&nbsp;</p> <p>Images are loaded like this:<br> &lt;img border=&quot;0&quot; src=&quot;image.axd?type=Cat1&amp;amp;id=e7810e9f-2abe-4a54-9b58-d82cd2b8fa6d&amp;amp;width=150&quot; /&gt;</p> <p>I cache the image like this in the HttpHandler:<br> <font size="2">context.Cache.Insert(cacheKey, picInfo);<br> context.Response.Clear();<br> context.Response.Cache.SetExpires(</font><font color="#008080" size="2">DateTime</font><font size="2">.Now.AddMinutes(expireInMinutes));<br> context.Response.Cache.SetCacheability(httpCacheability);<br> context.Response.Cache.SetValidUntilExpires(</font><font color="#0000ff" size="2">true</font><font size="2">);<br> context.Response.Cache.SetLastModified(</font><font color="#008080" size="2">DateTime</font><font size="2">.Now);<br> context.Response.Cache.SetMaxAge(</font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">TimeSpan</font><font size="2">(0, expireInMinutes, 0));</font></p> <p><font size="2">Then I output the image like this:<br> <font size="2">context.Response.ContentType = picInfo.ContentType;<br> </font></font><font size="2"><font size="2">context.Response.BufferOutput = </font> <font color="#0000ff" size="2">false</font><font size="2">;<br> context.Response.OutputStream.Write(picInfo.PicBytes, 0, picInfo.PicBytes.Length);</p> </font></font> 2006-08-07T18:20:10-04:001364695http://forums.asp.net/p/1015295/1364695.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler anyone??? 2006-08-08T18:34:44-04:001367170http://forums.asp.net/p/1015295/1367170.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler <p>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?</p> <p>if someone could at least point me in the right direction i'd be gratefull...</p> <p>thanks..</p> 2006-08-10T16:30:44-04:001368934http://forums.asp.net/p/1015295/1368934.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler <p>do you have a memory issue on the server?</p> <p>I believe cache will be dumped if aspnet doesn't have enough memory to work with?</p> <p>&nbsp;</p> 2006-08-12T02:20:08-04:001370301http://forums.asp.net/p/1015295/1370301.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler <p>thanks for replying...</p> <p>server's got 2GB of RAM. i am basically trying to get all of the images cached&nbsp;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. </p> <p>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?</p> <p>i will&nbsp;appreciate any reply.</p> <p>thank you</p> 2006-08-14T16:38:41-04:001379391http://forums.asp.net/p/1015295/1379391.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler <p>should i re-word the problem? i am still looking for an answer</p> 2006-08-24T04:10:55-04:001382514http://forums.asp.net/p/1015295/1382514.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler <p>I think you problem is in:</p> <p>context.Response.Cache.SetLastModified(<font color="#008080" size="2">DateTime</font><font size="2">.Now);</font></p> <p>You should actually&nbsp;get&nbsp;that&nbsp;date&nbsp;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.</p> <p>Cheers,</p> <p>Wes</p> 2006-08-28T12:32:24-04:001394446http://forums.asp.net/p/1015295/1394446.aspx/1?Re+Problems+Caching+dynamic+image+in+the+HttpHandlerRe: Problems Caching dynamic image in the HttpHandler <p>Hi</p> <p>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.</p> <p>check this blog to find how the asp.net request are handled and in which event you can use cache.</p> <p>http://www.vikramlakhotia.com/Post.aspx?postID=23&nbsp;</p> <p>vikram&nbsp;</p> <p><a href="http://www.vikramlakhotia.com/default.aspx?keyword=">Vikram's Blog</a> <br> </p> 2006-09-10T03:45:01-04:00