简体   繁体   中英

Working with the IE cache

I'm writing a program in C# using the WPF framework. I need to display images, and I'd like to cache them to avoid downloading them constantly.

I can code my own cache, however, IE already has a caching system. I can find code to read entries out of the IE cache, however I've found nothing dealing with the issue of adding items to the cache. Is there a good way to do it, or should I just implement a separate cache?

I would suggest you implement your own. You can't rely on the IE cache remaining consistent, or not being cleared by the user, or anything else. Unless you're actually embedding the IE browser in a control in your app, I see no reason to use it. Also, using your own cache allows you to create one that could be more fit for purpose (eg if you need to store thumbs, or extra metadata, or anything else).

Depending on how you're downloading the files, they may already be getting added to the cache. How are you downloading them now?

You can add items to the IE cache. Natively you have a couple of options: URLDownloadToCacheFile() will do it in one nice "easy" step. CommitUrlCacheEntry() is the hardcore way of doing it. I assume the sample you found uses FindFirst/FindNextUrlCacheEntry() to enumerate the cache, so you should be able to add the interop you need for CommitUrlCacheEntry() fairly easily.

However, as a former member of the IE team, I cannot recommend enough that you should not use the Wininet cache for anything. It is not reliable, it can be cleared out from underneath you, it frequently gets corrupted, it has some hard limits on how many things it can store, it's subject to various rules you don't understand, and it's going to be optimized for IE's usage, not yours.

Seriously, don't do this. If you really need a cache, write your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM