突然发现缓存这么好用
object obj = HttpRuntime.Cache.Get(key); if (obj == null ) { Debug.WriteLine(key + "被添加进Cache, 过期时间一分钟"); HttpRuntime.Cache.Add(key, "1", null, Cache.NoAbsoluteExpiration, new TimeSpan(TimeSpan.TicksPerMinute), CacheItemPriority.Normal, CacheItemRemovedCallback); } else { Debug.WriteLine(key + "已存在Cache中, 勿重复添加"); }
CacheItemRemovedCallback为缓存过期时的回调方法