如果你是一个新手,如果你刚接触MVC,如果你跟着置顶的那个项目,我们肯定会用到这里面的几个帮助类
它们都在Common类库下,大家一定要记住要点:取其精华去其糟粕,切勿拿来主义~
ApplicationCache.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Web; 6 7 namespace Common 8 { 9 public interface ICache 10 { 11 /// <summary> 12 /// 获取全局应用缓存 13 /// </summary> 14 /// <param name="key"></param> 15 /// <returns></returns> 16 object GetApplicationCache(string key); 17 /// <summary> 18 /// 设置全局应用缓存 19 /// </summary> 20 /// <param name="key"></param> 21 /// <param name="obj"></param> 22 void SetApplicationCache(string key, object obj); 23 /// <summary> 24 /// 删除全局应用缓存 25 /// </summary> 26 /// <param name="key"></param> 27 void RemoveApplicationCache(string key); 28 } 29 /// <summary> 30 /// 全局应用缓存 31 /// </summary> 32 public class ApplicationCache:ICache 33 { 34 #region ICache 成员 35 36 public object GetApplicationCache(string key) 37 { 38 return HttpContext.Current.Application[key]; 39 } 40 41 public void SetApplicationCache(string key, object obj) 42 { 43 HttpContext.Current.Application.Add(key, obj); 44 } 45 46 public void RemoveApplicationCache(string key) 47 { 48 HttpContext.Current.Application.Remove(key); 49 } 50 #endregion 51 } 52 }