Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I've got a Windows Forms Application which displays a listing of products derived from a dataset.
I'm doing this without using gridviews instead all the controls (labels buttons, and panels) are generated on the fly and positioned in codeland as they are expanded or collapsed by clicking buttons.

Each time there is an expand, collapse or scroll event it rebinds the entire listing from a dataset is which works quite well as its very fast.

I'm working on a new requirement which is to add an image thumbnail next to each item in the listing.

The ImageBox is also being generated dynamically but instead I've been deriving the image from the web server via http e.g.

VB
For ... Looping through dataset
  'bind other controls here
  SKUThumbNail(counter).LoadAsync("http://127.0.0.1/images/43234.jpg")
Next ... Iteration of Loop


Every time the dataset rebinds, the image is also reloaded from the webserver which is somewhat inefficient.

Before I go down the path of building an in memory image caching module for my application does anyone have any experience with this or know of any better approaches?

Any input appreciated, Thank you.

M:)
Posted
Updated 22-May-13 13:54pm
v3

1 solution

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
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900