Eric
Eric

Reputation: 851

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?

Upvotes: 2

Views: 1018

Answers (2)

i_am_jorf
i_am_jorf

Reputation: 54640

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.

Upvotes: 2

Dan Puzey
Dan Puzey

Reputation: 34218

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).

Upvotes: 2

Related Questions