This is a pretty good idea, which is easy to implement. Only you additionally would need to have a mechanism of deleting some of the cached images. How do you know if they never change?
You can store the images locally as regular image files; devise some system of naming them. It could be as simple as numeric numbers. You also would need some mechanism of defragmentation of image name sets. The image names should be stored in one of the key-based collections like
System.Collections.Generic.Dictionary<System.Uri, string>
, where the image
Uri
serves as a dictionary key, and second string generic parameter represents the local file name in your image storage. When you close the application and start again, you will need to store and then restore the dictionary itself. Dictionaries are not serializeable, but you can make your own simple mechanism of serialization. After all, this is as simple as a table of Uri/string pairs, so it can be as simple as a text file with those elements separated by end-of-line markers.
Please see:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.uri.aspx[
^].
You can consider two other collection classes based on key-pair storage and retrieval, which provide the
computational time complexity of O(1), which means that the search time asymptotically, for large volumes of data, does no depends on volume. Please see:
http://en.wikipedia.org/wiki/Big_O_notation[
^],
http://en.wikipedia.org/wiki/Time_complexity[
^],
http://en.wikipedia.org/wiki/Computational_complexity_theory[
^].
Two other classes are
SortedDictionary<Key, Value>
and
SortedList<Key, Value>
:
http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx[
^].
All three classes have nearly identical functionality, the selection of one can be based on different trade-off between performance and storage in memory. Just read MSDN help pages and experiment a bit.
—SA