How can I prevent URLDownloadToFile from retrieving from the cache?

无人久伴 提交于 2019-12-17 20:25:21

问题


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.


回答1:


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




回答2:


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.




回答3:


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

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




回答4:


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;


来源:https://stackoverflow.com/questions/75432/how-can-i-prevent-urldownloadtofile-from-retrieving-from-the-cache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!