存Cache方法:
HttpRuntime.Cache.Add( KeyName,//缓存名 KeyValue,//要缓存的对象 Dependencies,//依赖项 AbsoluteExpiration,//绝对过期时间 SlidingExpiration,//相对过期时间 Priority,//优先级 CacheItemRemovedCallback);//缓存过期引发事件 示例:
HttpRuntime.Cache.Add("CurrencyFundCodeCache", docs, null, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
鄙人自己写了一个示例
class Program { static void Main(string[] args) { if (HttpRuntime.Cache["arrKey"] != null) { MyClass myClass = HttpRuntime.Cache["myClass"] as MyClass; } else { MyClass myClass = new MyClass { ID = 1, Name = "张三", six = "男" }; HttpRuntime.Cache.Add("myClass", myClass, null, DateTime.Now.AddDays(3), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } Console.ReadKey(); Console.ReadKey(); } public class MyClass { public int ID { get; set; } public string Name { get; set; } public string six { get; set; } }
时间: 2024-11-25 02:26:56