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&id=e7810e9f-2abe-4a54-9b58-d82cd2b8fa6d&width=150" />
I cache the image like this in the HttpHandler:
context.Cache.Insert(cacheKey, picInfo);
context.Response.Clear();
context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(expireInMinutes));
context.Response.Cache.SetCacheability(httpCacheability);
context.Response.Cache.SetValidUntilExpires(true);
context.Response.Cache.SetLastModified(DateTime.Now);
context.Response.Cache.SetMaxAge(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);
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...
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?
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.
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.
emer
Member
150 Points
40 Posts
Problems Caching dynamic image in the HttpHandler
Aug 07, 2006 06:20 PM|LINK
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&id=e7810e9f-2abe-4a54-9b58-d82cd2b8fa6d&width=150" />
I cache the image like this in the HttpHandler:
context.Cache.Insert(cacheKey, picInfo);
context.Response.Clear();
context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(expireInMinutes));
context.Response.Cache.SetCacheability(httpCacheability);
context.Response.Cache.SetValidUntilExpires(true);
context.Response.Cache.SetLastModified(DateTime.Now);
context.Response.Cache.SetMaxAge(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);
emer
Member
150 Points
40 Posts
Re: Problems Caching dynamic image in the HttpHandler
Aug 08, 2006 06:34 PM|LINK
emer
Member
150 Points
40 Posts
Re: Problems Caching dynamic image in the HttpHandler
Aug 10, 2006 04:30 PM|LINK
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...
thanks..
jhouse
Participant
1856 Points
374 Posts
Re: Problems Caching dynamic image in the HttpHandler
Aug 12, 2006 02:20 AM|LINK
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?
emer
Member
150 Points
40 Posts
Re: Problems Caching dynamic image in the HttpHandler
Aug 14, 2006 04:38 PM|LINK
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
emer
Member
150 Points
40 Posts
Re: Problems Caching dynamic image in the HttpHandler
Aug 24, 2006 04:10 AM|LINK
should i re-word the problem? i am still looking for an answer
webbes
Participant
1987 Points
426 Posts
Re: Problems Caching dynamic image in the HttpHandler
Aug 28, 2006 12:32 PM|LINK
I think you problem is in:
context.Response.Cache.SetLastModified(DateTime.Now);
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.
Cheers,
Wes
vik20000in
All-Star
25882 Points
3993 Posts
MVP
Re: Problems Caching dynamic image in the HttpHandler
Sep 10, 2006 03:45 AM|LINK
Hi
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.
http://www.vikramlakhotia.com/Post.aspx?postID=23
vikram
Vikram's Blog
www.vikramlakhotia.com
Please mark the answer if it helped you