开发者

How can I check if I successfully cleared IE's cache?

开发者 https://www.devze.com 2022-12-23 15:52 出处:网络
I\'m clearing IE\'s cache programmatically using DeleteUrlCacheEntry() and I would like to verify that I did it correctly.

I'm clearing IE's cache programmatically using DeleteUrlCacheEntry() and I would like to verify that I did it correctly.

Should I expect the Temporary Internet Files folder to be empty after clearing the cache? (it isn't)

If not then what is the simplest way to determine whether the browser is using its cache when accessing a site?


Clarification: Our app interacts with the browser, I wrote two features, delete cookies and clear cache. It's pretty simple to check the delete cookies feature, login to a site, delete cookies, refresh, you've been logged out. However now QA opened a bug about clear cache not having emptied the Temporary Internet Files directory. I want to direct them how to test the feature but would like to avoid using an HTTP sniffer (like Y开发者_如何学Cuval suggested), is there a simpler way?


The wininet url cache is a bizarre and unholy creature. There are a few things to keep in mind. First: if you have IE open and it's doing things, some entries in the cache may be locked and you won't be able to delete them. Second: not all entries in the URL cache belong to IE, and not all entries in the containers in the temporary internet files folder are related to the browser URL cache. Third: depending on your version of IE there are various bugs where URL cache containers can become corrupt, causing their associated files to dangle. These bugs may or may not have been fixed for IE8 (I'm not sure).

The most correct way to ensure everything is gone is to use FindFirst/FindNextUrlCacheGroup(), then FindFirst/FindNextUrlCacheEntryEx() to enumerate the group items. Then delete the entries, then delete the group. History is a group, cookies are another group, etc. You can skip groups that you're not interested in.

The URL cache itself is just a glorified hash table (that lives in an index.dat file) that maps an URL to some metadata. The metadata contains the local cache filename of the resource. I'm not sure that deleting the URL cache entry actually deletes the resource on disk, you may have to do that yourself with DeleteFile().

Edit:

If you just want to clear everything, you can use the inetcpl.cpl,ClearMyTracksByProcess trick. The argument is a bitmask... I'm not sure which bit represents the TIF, but it's one of the lower eight so it should be relatively easy to figure it out. This only works on IE7 and IE8, however.

There are other ideas in the link as well.


Apparently the Temporary Internet Files directory should be empty!

I had a bug in my code due to the fact that FindFirstUrlCacheEntry states that you should pass "cookie:", "visited: or NULL and I thought that that means that:

Union("cookie:", "visited:") == NULL

This is not the case, I had to pass NULL and filter out the cookies (depending on the CacheEntryType field).

0

精彩评论

暂无评论...
验证码 换一张
取 消