Click to See Complete Forum and Search --> : What's this?


zingmatter
09-14-2005, 09:21 AM
I've been working on site for some time that was developed originally by someone else. At the top of the ASP coded pages he has put:

<%
With Response
.Buffer = True
.Expires = -1440 * 400
.Clear
End With
%>

Does anyone know what this means as I don't want to ask him having not done so for over 2 years (and so make me look stoopid).

Thanks

lmf232s
09-14-2005, 12:56 PM
That code code be writing like that or like this

Response.Buffer = True
Response.Expires = -1440 * 400
Response.Clear


With Buffer set to true it will allow you to display the data to the screen as it is process with the help of
Response.flush.

SO lets say reading in 200 records and its a lenght query, instead of waiting until the page is finished loading to display all the data you could do
Response.flush after each record as long as .buffer = True. This will send the output to the client

Do while not objrs.EOF
'do something
Response.flush
Loop

Response.Expires
This basically says that the cached version of this page will expire at a certian point.

When you hit the back button on your browser, it does not always rerun the page, but grabs a cached version of the page. But by setting the page to expire, then when you hit the back button, if the page has expired then it will rerun the page instead of grabbing a cached copy.

If you place this at the top of your page
Response.ExpiresAbsolute = Now() -1
Then it will expire after it runs and everytime you access this page it will rerun an new copy.

Response.clear clears any buffered response to the client. This is only used when buffer = True. It just clears the buffer.

do a goole on all three and youll see examples of them all.

zingmatter
09-14-2005, 01:36 PM
Excellent. THanks for your very complete reply.

Why write -1440 * 400 rather than -576000?

lmf232s
09-14-2005, 01:42 PM
Dont know, the value could of been
0, -1 through -1000000000 and it would do basically the same thing.

That you would have to ask but the main thing that line is doing is just expiring the cached page.

Sometimes there is no reasoning behing the madness.

HaganeNoKokoro
09-14-2005, 01:43 PM
I thought response buffering put the response in a buffer until it's all ready.

The reason to do this is so that you can send headers even in the middle of your page. Normally, once you start sending output, you can't send headers (such as Location (redirect) or cookies). With response buffering, you haven't sent any output to the client, so the headers get sent first (even if they're in the middle of your output).

lmf232s
09-14-2005, 01:47 PM
It does put the response in the buffer but you can flush the data any time you like to send the out put to the client.

HaganeNoKokoro
09-14-2005, 01:50 PM
So... without buffering, it would just flush the data every time you did a write, right? Then, why buffer at all (given that the advantage you state is that you can send output immediately, but if you don't buffer, it will happen anyway)? I'll agree it gives you more control over how you send the data.

lmf232s
09-14-2005, 02:08 PM
I dont have a real good reason to use it, except for what you mentioned.
All i know is you can store the it to the buffer and then flush it or you can just output directly to the client w/out the buffer.

Dont have a real life example.

russell_g_1
09-14-2005, 02:26 PM
its more efficient to use buffering. iis will only attempt to send data to the client when the page has finished being generated or it is flushed, otherwise it will send the data in tiny little bits.

russell_g_1
09-14-2005, 02:30 PM
on the subject of controlling whether or not a page is cached, i always put these in.

Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "cache-control", "no-store"