title: Removing the oldest item from a Dictionary
body: <p>I'm working with a WPF application tasked with displaying a large amount of bitmap files. In the future I plan to implement a solution using vector graphics, but for now I have this problem: </p>
  
  <p>To minimize the time my application reads files from disk I created a <code>Dictionary&lt;string, BitmapImage&gt;</code>  (where string is the file path of the image) to hold the most lately used images. If an image is requested that was recently viewed, the program fetches it from the <code>Dictionary</code> instead of from the disk. However, as the number of images viewed grows, so does the amount of RAM used by the program. So my idea was holding a limited amount of images, and as a new one is loaded from disk, overwrite the oldest one from my <code>Dictionary</code>.</p>
  
  <p>How would I go about doing this in the best way possible? I've looked into using a <code>SortedDictionary</code> but can't figure out how to write an <code>IComparer</code> as neither the <code>keys</code> or <code>items</code> have any information about the time/order they were added.</p>
  
  <p>Would keeping a separate <code>SortedDictionary&lt;DateTime, string&gt;</code> with a <code>DateTime IComparer</code> be a sensible solution? In that way, when a new file is added the path to the oldest added file can be found, and matched with the correct image in my <code>Dictionary</code>. This kind of feels like a to advanced solution though. Any overlooked or built-in solutions?</p>