I\'m trying to use the Caching Application Block to cache some images (these images take a long time to render)
BitmapSource bitmapSource; ///some bitmap s
but isn't _cache.Add() making a copy (via Serialization) before it exits?
Not necessarily. If it is "in process" it will just store the object reference; Stream
isn't really very serializable anyway (a Stream
is a hose, not a bucket).
You want to store the BLOB - not the Stream
:
_cache.Add(someId, stream.ToArray());
...
byte[] blob = _cache.GetData(someId);
if(blob != null) {
using(Stream inStream = new MemoryStream(blob)) {
// (read)
}
}