using System; namespace Quiz.Utility.Cache { /// /// 提供缓存项的基本包装。 /// /// public sealed class CacheItem : IDisposable { public CacheItem(CacheItemInitCallback initcall) { this.initcall = initcall; syncroot = new object(); } ~CacheItem() { this.Dispose(); } public void Dispose() { initcall -= initcall; this.cachedata = default(T); } CacheItemInitCallback initcall; T cachedata; object syncroot; public T CacheData { get { return this.cachedata; } } public void InitCache() { lock (this.syncroot) { cachedata = initcall(); } } } }