473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

cache (VaryByParam) doesn't work

Hi,

I have image.aspx that can accept 3 query string parameters (FolderID,
ImageID, Size) and it returns full jpg image or image thumbnail (depending
on size).

I included the following directive:

<%@ OutputCache Duration="3600" VaryByParam="FolderID;ImageID;Size" %>

to cache images/thumbnails for an hour

The images ate taken programmaticaly from file system and returned this way:

Response.ContentType = "image/jpeg";

image.Save(Response.OutputStream,System.Drawing.Im aging.ImageFormat.Jpeg);
// for thumbnails

//or

//Response.WriteFile(imagepath); // for full images

Response.End;

But I noticed that caching doesn't work. After first request for specific
picture all subsequent calls execute the code over and over again instead
taking the first result from cache. What I am missing and how to fix it?

Regards,

Dmitry

Nov 18 '05 #1
7 6572
I have been in a similar situation before.... here is what i suggest you do.

a. instead of writing an aspx to handle image rendering and cacheing.. use a
custom handler .ashx (about 5 % faster than .aspx).
b. instead of caching image and its thumbnail (i presume you getting
thumbnail by calling Image.GetThumbnailImage()) you could just catch the
image and resize it every time.. it will balance the extra memory
utilisation.
c. Do you really want to catch for one hour ? how many images do you have
and what is the configuration of the server ?
d. use smart caching.. ie use sliding time expiration and use a value like
say 10 mins.. if the image is accessed in the next 10 mins it will be reset.
you will just overload the server by caching for an hour..
e. i went through this article like an year back and i almost does
everything you are trying to do. you might not want a custom extension.. if
so just use .ashx.

http://www.microsoft.com/belux/nl/ms...tphandler.mspx

--

Regards,

Hermit Dave (D'way)
http://hdave.blogspot.com

"Dmitry Duginov" <di**@nospam.nospam> wrote in message
news:uq**************@TK2MSFTNGP15.phx.gbl...
Hi,

I have image.aspx that can accept 3 query string parameters (FolderID,
ImageID, Size) and it returns full jpg image or image thumbnail (depending
on size).

I included the following directive:

<%@ OutputCache Duration="3600" VaryByParam="FolderID;ImageID;Size" %>

to cache images/thumbnails for an hour

The images ate taken programmaticaly from file system and returned this way:
Response.ContentType = "image/jpeg";

image.Save(Response.OutputStream,System.Drawing.Im aging.ImageFormat.Jpeg);
// for thumbnails

//or

//Response.WriteFile(imagepath); // for full images

Response.End;

But I noticed that caching doesn't work. After first request for specific
picture all subsequent calls execute the code over and over again instead
taking the first result from cache. What I am missing and how to fix it?

Regards,

Dmitry


Nov 18 '05 #2
Well, thank you, maybe I'll follow some of your recommendations, but now I'd
like to know why caching doesn't work in my current solution.

Dmitry.

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have been in a similar situation before.... here is what i suggest you do.
a. instead of writing an aspx to handle image rendering and cacheing.. use a custom handler .ashx (about 5 % faster than .aspx).
b. instead of caching image and its thumbnail (i presume you getting
thumbnail by calling Image.GetThumbnailImage()) you could just catch the
image and resize it every time.. it will balance the extra memory
utilisation.
c. Do you really want to catch for one hour ? how many images do you have
and what is the configuration of the server ?
d. use smart caching.. ie use sliding time expiration and use a value like
say 10 mins.. if the image is accessed in the next 10 mins it will be reset. you will just overload the server by caching for an hour..
e. i went through this article like an year back and i almost does
everything you are trying to do. you might not want a custom extension.. if so just use .ashx.

http://www.microsoft.com/belux/nl/ms...tphandler.mspx
--

Regards,

Hermit Dave (D'way)
http://hdave.blogspot.com
"Dmitry Duginov" <di**@nospam.nospam> wrote in message
news:uq**************@TK2MSFTNGP15.phx.gbl...
Hi,

I have image.aspx that can accept 3 query string parameters (FolderID,
ImageID, Size) and it returns full jpg image or image thumbnail (depending on size).

I included the following directive:

<%@ OutputCache Duration="3600" VaryByParam="FolderID;ImageID;Size" %>

to cache images/thumbnails for an hour

The images ate taken programmaticaly from file system and returned this

way:

Response.ContentType = "image/jpeg";

image.Save(Response.OutputStream,System.Drawing.Im aging.ImageFormat.Jpeg); // for thumbnails

//or

//Response.WriteFile(imagepath); // for full images

Response.End;

But I noticed that caching doesn't work. After first request for specific picture all subsequent calls execute the code over and over again instead taking the first result from cache. What I am missing and how to fix it?

Regards,

Dmitry



Nov 18 '05 #3
Hi Dmitry,

Thanks for your posting. As for the problem you mentioned, I've also tested
and found that. It is likely due to the the asp.net's outputCache's
internal mechanism on evaluating the comming request's CAchekey. Anyway,
I'll do some further consulting to see whether there is any detailed
explanition. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Thanks for your posting. As for the problem you mentioned, I've also tested and found that. It is likely due to the the asp.net's outputCache's
internal mechanism on evaluating the comming request's CAchekey. Anyway,
I'll do some further consulting to see whether there is any detailed
explanition. Thanks.

Regards,

Steven Cheng
Microsoft Online Support


Thank you Steven, I'll try some workarounds meanwhile. I hope you'll find
what's going on and let me know.

Dmitry

Nov 18 '05 #5
Hi Dmitry,

After some further research, I think the problem is caused by the
Response.End(or Response.Flush) we called after we output the image. This
will make the current request's thread be terminated and the response
content be sent to client immediatly, so some further ASP.NET page
processing haven't been finished and the Output Caching is one thing
that'll be done at that time, so we need to remove the Response.End or
Response.Flush after we write out the image stream. Below is a sample page
code, I've tested on my side.

========================
private void Page_Load(object sender, System.EventArgs e)
{
RenderImage(DateTime.Now.ToLongTimeString());

}

private void RenderImage(string text)
{
Response.ClearContent();
Response.ContentType="Image/gif";
Bitmap bmp = new Bitmap(400,300);
Graphics graphic = Graphics.FromImage(bmp);
graphic.FillRectangle(new
SolidBrush(Color.Yellow),0,0,bmp.Width,bmp.Height) ;
graphic.DrawString(text,new Font("Tahoma",
30,System.Drawing.FontStyle.Bold),new
SolidBrush(Color.Blue),50,50,StringFormat.GenericD efault);
bmp.Save(Response.OutputStream,System.Drawing.Imag ing.ImageFormat.Gif);
bmp.Dispose();

//don't call Response.End or Response.Flush here
}
=========================

Please have a try to see whether it works. Hope help. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:yF**************@cpmsftngxa10.phx.gbl...
Hi Dmitry,

After some further research, I think the problem is caused by the
Response.End(or Response.Flush) we called after we output the image. This
will make the current request's thread be terminated and the response
content be sent to client immediatly, so some further ASP.NET page
processing haven't been finished and the Output Caching is one thing
that'll be done at that time, so we need to remove the Response.End or
Response.Flush after we write out the image stream. Below is a sample page
code, I've tested on my side.


Thank you, your example works fine. But I already rebuild this thing using
HttpHandler and explicit data caching.

It would be good to mention thit Response.End and .Flush behavior in
connection with OutputCache somewhere in documentation...

Regards,
Dmitry
Nov 18 '05 #7
Thanks for your followup Dmitry,

Well, I'm glad that you've alreay worked through the problem by using the
HttpHandler, infact, that's also the recommended means for service image in
web application. Also, as for this problem, it is also my mistake that I
should have found the cause early( the Response.End break down the caching
mechanism). Anyway, thanks again for your posting and understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom Kiefer | last post by:
Question: If I have an ASP.NET User Control which defines/exposes a property that the page can use to specify a mode or data subset for the control to use, is there a way to tell the @OutputCache...
7
by: moondaddy | last post by:
I have a products catalogue that I'm putting online and there will be between 20 to 50 different pages of products. Each page contains a datagrid of products for a given category. However, the...
4
by: A.M | last post by:
Hi, I underestand that I can change a user-control's cache parameters and timeout by attributes like this: <%@ OutputCache Duration="60" VaryByParam="none" %> Is it possible to define Cache...
7
by: A.M | last post by:
Hi, How can I change the duration of user control's cache inside asp.net's C# code? Any help would be apprecited, Alan
1
by: Edward Wilde | last post by:
Hi, Does anyone know how to examine items in the ASP.NET cache that are added using the OutputCache directive in framework 1.1 i.e. <%@ OutputCache Duration="300" VaryByParam="None"...
2
by: jack | last post by:
Now here i have a doubt the explorer maintains the cache for 300 seconds when the code is in html code like the one which is below :- <%@ OutputCache Duration="300" VaryByParam="none" %> But...
0
by: SharpSmith | last post by:
hi all i have a strange problem with caching very simple cache test page with fallowing code is not cached at all(browser/server whatever): <%@ Register TagPrefix="uc1"...
3
by: ary | last post by:
I try to create a weblog host site! in this case i can't use cache for every page because that cause to be my Server ram full of caching page. but if I can save cache in hard disk my problem...
1
by: =?ISO-8859-1?Q?Jo=E3o_Maia?= | last post by:
Hello there, I'm using Cache VaryByParam on a page and I'm not getting the behaviour I expected. Here's what happens: - I have page a.aspx declared with Cache VaryByParam="name" - Page a.aspx...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.