Discussion:
Is URLDownloadToFile subject to local caching?
(too old to reply)
Joseph Geretz
2003-09-19 21:22:40 UTC
Permalink
Does URLDownloadToFile behave like IE itself does when downloading a file?
That is, are downloaded files cached in the local document cache? I'm not at
the office now, but I just got a report that on the server, a data file was
rolled back to an older version, yet the remote client was still picking up
the newer data file, which didn't even exist on the server anymore!

Without being on-site, the only thing I can think of off the bat, is that
this sounds very much like the way IE itself, in many case, only downloads a
page off the server if the page is newer than the page in local cache. Does
URLDownloadTofile behave like this? If so, is there anyway to bypass the
local cache entirely when using URLDownloadToFile?

Or do I need to be looking in another direction altogether?

Thanks for your help.

- Joe Geretz -
Larry Serflaten
2003-09-19 21:34:42 UTC
Permalink
Post by Joseph Geretz
Does URLDownloadToFile behave like IE itself does when downloading a file?
That is, are downloaded files cached in the local document cache? I'm not at
the office now, but I just got a report that on the server, a data file was
rolled back to an older version, yet the remote client was still picking up
the newer data file, which didn't even exist on the server anymore!
Without being on-site, the only thing I can think of off the bat, is that
this sounds very much like the way IE itself, in many case, only downloads a
page off the server if the page is newer than the page in local cache. Does
URLDownloadTofile behave like this? If so, is there anyway to bypass the
local cache entirely when using URLDownloadToFile?
Or do I need to be looking in another direction altogether?
I'd wonder if the server is sending it from a cache...

There is a D/L to cache API, so I would suspect your ToFile is
doing just that, going to a file.

LFS
Eduardo A. Morcillo [MS MVP VB]
2003-09-19 23:24:51 UTC
Permalink
Post by Joseph Geretz
Does URLDownloadToFile behave like IE itself does when downloading a
file? That is, are downloaded files cached in the local document
cache?
Yes, it downloads the file to the IE cache and then gives you a copy.
Post by Joseph Geretz
If so, is there anyway to bypass the local cache entirely when using
URLDownloadToFile?
It's possible if you implement the callback interface and pass a reference
in the URLDownloadToFile call (the last parameter). There's a sample in my
site that shows how to do it.
--
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Larry Serflaten
2003-09-20 01:13:14 UTC
Permalink
Post by Eduardo A. Morcillo [MS MVP VB]
Post by Joseph Geretz
Does URLDownloadToFile behave like IE itself does when downloading a
file? That is, are downloaded files cached in the local document
cache?
Yes, it downloads the file to the IE cache and then gives you a copy.
I wish MS would get their documentation inline with the implementation.

URLDownloadToFile:
Downloads bits from the Internet and saves them to a file.

URLDownloadToCacheFile:
Downloads data into the Internet cache and returns the file name
of the cache location for retrieving the bits.

If URLDownloadToFile actually saves to the IE cache, why would they
need the other one???

LFS
Eduardo A. Morcillo [MS MVP VB]
2003-09-20 03:54:29 UTC
Permalink
Post by Larry Serflaten
If URLDownloadToFile actually saves to the IE cache, why would they
need the other one???
By default URLDownloadToFile download gets the file from the cache. If it's
not there it will download it to the cache and then makes a copy. If you
implement the callback you can set the flags to ignore the cache and get the
file from the server or not write it to the cache.

The other function makes possible to open the file directly from the cache
folder without creating a copy. This is what media player does when you open
an .asx file from the web.
--
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Larry Serflaten
2003-09-20 10:00:51 UTC
Permalink
"Eduardo A. Morcillo [MS MVP VB]" <emorcilloATmvps.org>
Post by Eduardo A. Morcillo [MS MVP VB]
Post by Larry Serflaten
If URLDownloadToFile actually saves to the IE cache, why would they
need the other one???
By default URLDownloadToFile download gets the file from the cache. If it's
not there it will download it to the cache and then makes a copy. If you
implement the callback you can set the flags to ignore the cache and get the
file from the server or not write it to the cache.
The other function makes possible to open the file directly from the cache
folder without creating a copy. This is what media player does when you open
an .asx file from the web.
OK, thanks, but I will say again....
I wish MS would get their documentation inline with the implementation.

:-(
LFS
Joseph Geretz
2003-09-21 01:45:45 UTC
Permalink
Hi Eduardo,

Thanks for your reply.
Post by Eduardo A. Morcillo [MS MVP VB]
It's possible if you implement the callback interface and pass a reference
in the URLDownloadToFile call (the last parameter). There's a sample in my
site that shows how to do it.
I was on your site and found your AsyncDownload Class. Is this the sample
you are referring to? Are you suggesting that I implement the
IBindStatusCallBack? I don't see how this will help me. Maybe this is along
the lines of Larry's complaint regarding MS documentation (or sometimes,
lack thereof) but here's what I find on MSDN regarding this interface:

http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/moniker/reference/functions/urldownloadtofile.asp

lpfnCB
Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile
calls this interface's IBindStatusCallback::OnProgress method on a
connection activity, including the arrival of data.
IBindStatusCallback::OnDataAvailable is never called. Implementing
IBindStatusCallback::OnProgress allows a caller to implement a user
interface or other progress monitoring functionality. It also allows the
download operation to be canceled by returning E_ABORT from the
IBindStatusCallback::OnProgress call. This can be set to NULL.

According to the doc, this interface provides callback notification on the
progress of the download. but for whatver reason (by design, no doubt :-(,
OnDataAvailable is never called. So how does this help me avoid the cache
when downloading the file?

Thanks for your help,

- Joe Geretz -
Joseph Geretz
2003-09-21 01:56:41 UTC
Permalink
Flash! I found this little nugget at

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20269291.html

See the Accepted Answer by Ark
----------------------------------
...
BTW, MSDN says that dwReserved member of this function should be 0. Lie! IE
5.0 and above use this member for:

dwReserved = 1 - Force to download from URL
dwReserved = 2 - Force to download from Cache
----------------------------------

This might be the quick and simple solution. I'll give this a shot and let
you know...

(And I think we can all sympathize with Larry's comments regarding MS
documentation.)

Google - ya gotta love it!

- Joe Geretz -
Post by Joseph Geretz
Hi Eduardo,
Thanks for your reply.
Post by Eduardo A. Morcillo [MS MVP VB]
It's possible if you implement the callback interface and pass a reference
in the URLDownloadToFile call (the last parameter). There's a sample in my
site that shows how to do it.
I was on your site and found your AsyncDownload Class. Is this the sample
you are referring to? Are you suggesting that I implement the
IBindStatusCallBack? I don't see how this will help me. Maybe this is along
the lines of Larry's complaint regarding MS documentation (or sometimes,
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/moniker/reference/functions/urldownloadtofile.asp
Post by Joseph Geretz
lpfnCB
Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile
calls this interface's IBindStatusCallback::OnProgress method on a
connection activity, including the arrival of data.
IBindStatusCallback::OnDataAvailable is never called. Implementing
IBindStatusCallback::OnProgress allows a caller to implement a user
interface or other progress monitoring functionality. It also allows the
download operation to be canceled by returning E_ABORT from the
IBindStatusCallback::OnProgress call. This can be set to NULL.
According to the doc, this interface provides callback notification on the
progress of the download. but for whatver reason (by design, no doubt :-(,
OnDataAvailable is never called. So how does this help me avoid the cache
when downloading the file?
Thanks for your help,
- Joe Geretz -
Eduardo A. Morcillo [MS MVP]
2003-09-21 04:29:51 UTC
Permalink
Post by Joseph Geretz
I was on your site and found your AsyncDownload Class. Is this the
sample you are referring to?
Yes.
Post by Joseph Geretz
Are you suggesting that I implement the IBindStatusCallBack?
Yes.
Post by Joseph Geretz
So how does this help me avoid the cache when downloading the file?
The interface not only provides progress info, it also allows to control the
download. When used with URLDownloadToFile the methods are called in the
following order:

1) GetBindInfo
2) OnStartBinding
3) OnProgress (called several times)
4) OnStopBinding

OnDataAvailable is not called by URLDownloadToFile (its used by
URLOpenStream and URLOpenBlockingStream APIs). The GetBindInfo method is
called to get how the data will be downloaded. Using this method you can
tell the function if the data has to be read from the cache, from the net,
from the cache if net fails, etc. Also you can tell the function which HTTP
method has to use to get the data and set the data if you use POST.

Also the callback object can implement other interfaces:

* IAuthenticate, to authentica the user if required by the server.
* IHttpNegotiate, to set and get the HTTP header.
* IWindowForBindingUI, to show messages (like the warning message for
invalid security certificate on an https site).
--
Eduardo A. Morcillo [MS MVP]
http://www.mvps.org/emorcillo
Loading...