Is there a bu开发者_运维知识库ilt-in in-memory, LRU cache for Silverlight? I can write my own from scratch, but I would rather have one built by the pros.
The Caching Application Block is included in Enterprise Library for Silverlight.
InMemoryCache is in Microsoft.Practices.EnterpriseLibrary.Caching.Silverlight.dll.
var cache = new InMemoryCache("cache", 100, 50, TimeSpan.FromSeconds(1));
var item = new object();
cache.Add("key", item, DateTimeOffset.Now.AddSeconds(1));
var cachedItem = cache.Get("key");
Assert.AreSame(item, cachedItem);
Thread.Sleep(TimeSpan.FromSeconds(5));
Assert.IsNull(cache.Get("key"));
精彩评论