public class DataCache...{ public static readonly Singleton Intance = new Singleton(); private Singleton() ...{ // // TODO: Add constructor logic here // } /**//// <summary> /// 数据 /// </summary> private Hashtable hsData = new Hashtable(); private Queue markQueue = new Queue(); /**//// <summary> /// 缓存间隔(MIN) /// </summary> private const int Interval = 300; /**//// <summary> /// 获取当前应用程序指定CacheKey的Cache值 /// </summary> /// <param name="CacheKey"></param> /// <returns></returns> public object GetCache(string CacheKey) ...{ ClearTimeOut(); if (hsData.ContainsKey(CacheKey)) ...{ return hsData[CacheKey]; } else ...{ return null; } } /**//// <summary> /// 检测是否包含 /// </summary> /// <param name="CacheKey"></param> /// <returns></returns> public bool Contain(string CacheKey) ...{ return hsData.Contains(CacheKey); } /**//// <summary> /// 设置当前应用程序指定CacheKey的Cache值 /// </summary> /// <param name="CacheKey"></param> /// <param name="objObject"></param> public void SetCache(string CacheKey, object objObject) ...{ ClearTimeOut(); if (hsData.ContainsKey(CacheKey)) ...{ hsData.Remove(CacheKey); } hsData.Add(CacheKey, objObject); TimerKeeper item = new TimerKeeper(); item.Key = CacheKey; item.Stime = DateTime.Now; markQueue.Enqueue(item); } /**//// <summary> /// 清除过期的数据 /// </summary> private void ClearTimeOut() ...{ while (markQueue.Count>0) ...{ TimerKeeper item = (TimerKeeper)(markQueue.Peek()); TimeSpan span=DateTime.Now.Subtract(item.Stime); if (span.Seconds > Interval) ...{ markQueue.Dequeue(); hsData.Remove(item.Key); } else ...{ break; } } } private struct TimerKeeper ...{ public string Key; public DateTime Stime; }}