开发者

Working with the IE cache

开发者 https://www.devze.com 2022-12-29 16:10 出处:网络
I\'m writing开发者_StackOverflow社区 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'm writing开发者_StackOverflow社区 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?


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.


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 (e.g. if you need to store thumbs, or extra metadata, or anything else).

0

精彩评论

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

关注公众号