如何防止 URLDownloadToFile 从缓存中检索?

发布于 2024-07-05 12:02:24 字数 76 浏览 10 评论 0原文

我正在使用 URLDownloadToFile 从网站检索文件。 后续调用将返回原始文件而不是更新版本。 我假设它正在检索缓存的版本。

I am using URLDownloadToFile to retrieve a file from a website. Subsequent calls return the original file rather than an updated version. I assume it is retrieving a cached version.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

潜移默化 2024-07-12 12:02:24

在调用 URLDownloadToFile 之前使用相同的 URL 调用 DeleteUrlCacheEntry。
您需要链接 Wininet.lib

Call DeleteUrlCacheEntry with the same URL just prior to calling URLDownloadToFile.
You will need to link against Wininet.lib

岁月如刀 2024-07-12 12:02:24

是的,它默认提取文件的缓存版本。 要完全避免缓存文件,请在 lpfnCB 中传递 IBindStatusCallback 对象
URLDownloadToFile() 的参数。 在实现的 IBindStatusCallback::GetBindInfo() 方法中,在通过 grfBINDF 参数返回的值中包含 BINDF_GETNEWESTVERSION 标志,也可以选择包含 BINDF_NOWRITECACHE 标志。 如果您希望更新缓存文件(如果存在)而不是跳过,请指定 BINDF_RESYNCHRONIZE 标志。

Yes, it is pulling a cached version of the file by default. To avoid the cache file completely, pass an IBindStatusCallback object in the lpfnCB
parameter of URLDownloadToFile(). In your implemented IBindStatusCallback::GetBindInfo() method, include the BINDF_GETNEWESTVERSION flag, and optionally also the BINDF_NOWRITECACHE flag, in the value you return via the grfBINDF parameter. If you want the cache file, if present, to be updated instead of skippe, specify the BINDF_RESYNCHRONIZE flag instead.

一江春梦 2024-07-12 12:02:24

您能否在 URL 末尾添加一个无害的查询参数?

https://stackoverflow.com/?CacheBuster=1020am

Could you add a harmless query parameter to the end of your URL?

https://stackoverflow.com/?CacheBuster=1020am

巾帼英雄 2024-07-12 12:02:24

清理缓存

// Limpa cache do Internet Explorer
procedure DeletaIECache;
var
     lpEntryInfo: PInternetCacheEntryInfo;
     hCacheDir: LongWord;
     dwEntrySize: LongWord;
begin
     dwEntrySize := 0;
     FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize) ;
     GetMem(lpEntryInfo, dwEntrySize) ;
     if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
     hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize) ;
     if hCacheDir <> 0 then
     begin
         repeat
         DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName) ;
         FreeMem(lpEntryInfo, dwEntrySize) ;
         dwEntrySize := 0;
         FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize) ;
         GetMem(lpEntryInfo, dwEntrySize) ;
         if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
         until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize) ;
     end;
     FreeMem(lpEntryInfo, dwEntrySize) ;
     FindCloseUrlCache(hCacheDir) ;
end;

clean cache

// Limpa cache do Internet Explorer
procedure DeletaIECache;
var
     lpEntryInfo: PInternetCacheEntryInfo;
     hCacheDir: LongWord;
     dwEntrySize: LongWord;
begin
     dwEntrySize := 0;
     FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize) ;
     GetMem(lpEntryInfo, dwEntrySize) ;
     if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
     hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize) ;
     if hCacheDir <> 0 then
     begin
         repeat
         DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName) ;
         FreeMem(lpEntryInfo, dwEntrySize) ;
         dwEntrySize := 0;
         FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize) ;
         GetMem(lpEntryInfo, dwEntrySize) ;
         if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
         until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize) ;
     end;
     FreeMem(lpEntryInfo, dwEntrySize) ;
     FindCloseUrlCache(hCacheDir) ;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文