Cnic.CacheHelper<T>

  1     public class UserBLL
  2     {
  3         public class UserInfo
  4         {
  5             public int ID { get; set; }
  6             public string Email { get; set; }
  7             public string UserName { get; set; }
  8         }
  9 
 10         public UserInfo GetModel(int id)
 11         {
 12             return null;//dal.GetModel(id);
 13         }
 14         public UserInfo GetModelByCache(int id)
 15         {
 16             CacheHelper<UserInfo> cacheHelper = new CacheHelper<UserInfo>();
 17             cacheHelper.CacheTime = 10000;
 18             cacheHelper.CacheKey = "Model.UserInfo." + id;
 19             return cacheHelper.GetValue(id, new CacheHelper<UserInfo>.IntHandel(GetModel));
 20         }
 21 
 22         public UserInfo GetModel(string email)
 23         {
 24             return null;//dal.GetModel(email);
 25         }
 26         public UserInfo GetModelByCache(string email)
 27         {
 28             CacheHelper<UserInfo> cacheHelper = new CacheHelper<UserInfo>();
 29             cacheHelper.CacheTime = 10000;
 30             cacheHelper.CacheKey = "Model.UserInfo." + email;
 31             return cacheHelper.GetValue(email, new CacheHelper<UserInfo>.StringHandel(GetModel));
 32         }
 33 
 34         public int Update(UserInfo model)
 35         {
 36             int rtun = 0;//dal.Update(model);
 37             if (rtun > 0)
 38             {
 39                 new CacheHelper<UserInfo>() { CacheKey= "Model.UserInfo." + model.Email }.Remove();
 40                 new CacheHelper<UserInfo>() { CacheKey = "Model.UserInfo." + model.ID }.Remove();
 41             }
 42             return rtun;
 43         }
 44     }
 45 
 46     public class CacheHelper<T>
 47     {
 48         /// <summary>
 49         /// 多长时间没有访问后过期
 50         /// </summary>
 51         /// <param name="key"></param>
 52         /// <param name="value"></param>
 53         /// <param name="time"></param>
 54         public static void Insert(string key, object value, TimeSpan time)
 55         {
 56             if (value != null)
 57             {
 58                 System.Web.HttpRuntime.Cache.Insert(
 59                    key,
 60                    value,
 61                    null,
 62                    System.Web.Caching.Cache.NoAbsoluteExpiration,
 63                    time);
 64             }
 65         }
 66         /// <summary>
 67         /// 指定时间过期
 68         /// </summary>
 69         /// <param name="key"></param>
 70         /// <param name="value"></param>
 71         /// <param name="time">DateTime.UtcNow.AddSeconds(10)</param>
 72         public static void Add(string key, object value, DateTime time)
 73         {
 74             if (value != null)
 75             {
 76                 System.Web.HttpRuntime.Cache.Add(
 77                     key,
 78                     value,
 79                     null,
 80                     time,//10秒
 81                     System.Web.Caching.Cache.NoSlidingExpiration,
 82                     System.Web.Caching.CacheItemPriority.High,
 83                     null);
 84             }
 85         }
 86 
 87         public static object Remove(string key)
 88         {
 89             if (key == null) { return null; }
 90             return System.Web.HttpRuntime.Cache.Remove(key);
 91         }
 92 
 93         public class CacheObject
 94         {
 95             //public bool IsExist { get; set; }
 96             public T Value { get; set; }
 97         }
 98 
 99         public string CacheKey { get; set; }
100         public int CacheTime { get; set; }
101         public IntHandel CacheIntHandel { get; set; }
102         public StringHandel CacheStringHandel { get; set; }
103 
104         public delegate T IntHandel(int id);
105         public delegate T StringHandel(string key);
106 
107 
108         public T GetValue(int id, IntHandel handel)
109         {
110             CacheObject rtun = System.Web.HttpRuntime.Cache[CacheKey] as CacheObject;
111             if (rtun == null)
112             {
113                 rtun = new CacheObject();
114                 rtun.Value = handel(id);
115                 //rtun.IsExist = rtun.Value != null;
116                 Insert(CacheKey, rtun, TimeSpan.FromSeconds(CacheTime));
117             }
118             return rtun.Value;
119         }
120         public T GetValue(string key, StringHandel handel)
121         {
122             CacheObject rtun = System.Web.HttpRuntime.Cache[CacheKey] as CacheObject;
123             if (rtun == null)
124             {
125                 rtun = new CacheObject();
126                 rtun.Value = handel(key);
127                 //rtun.IsExist = rtun.Value != null;
128                 Insert(CacheKey, rtun, TimeSpan.FromSeconds(CacheTime));
129             }
130             return rtun.Value;
131         }
132         public T Remove()
133         {
134             CacheObject rtun = System.Web.HttpRuntime.Cache[CacheKey] as CacheObject;
135             if (rtun == null) { return default(T); }
136             return rtun.Value;
137         }
138     }

 

转载于:https://www.cnblogs.com/CodeBase/p/3150716.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
//SHA1.c #include <stdio.h> #include <string.h> #include <Windows.h> void creat_w( char input[64],unsigned long w[80]){ int i,j; unsigned long temp,temp1; for(i=0;i<16;i++){ j=4*i; w[i]=((long)input[j])<<24 |((long)input[1+j])<<16|((long)input[2+j])<<8|((long)input[3+j])<<0; } for(i=16;i<80;i++){ w[i]=w[i-16]^w[i-14]^w[i-8]^w[i-3]; temp=w[i]<<1; temp1=w[i]>>31; w[i]=temp|temp1; } } void ms_len(long a,char intput[64]){ unsigned long temp3,p1; int i,j; temp3=0; p1=~(~temp3<<8); for(i=0;i<4;i++){ j=8*i; intput[63-i]=(char)((a&(p1<<j))>>j); } } int main(){ unsigned long H0=0x67452301,H1=0xefcdab89,H2=0x98badcfe,H3=0x10325476,H4=0xc3d2e1f0; unsigned long A,B,C,D,E,temp,temp1,temp2,temp3,k,f; int i,flag; unsigned long w[80]; char input[64]; long x;int n; printf("输入明文:"); scanf("%s",input); n=strlen(input); if(n<57){ x=n*8; ms_len(x,input); if(n==56){ for(i=n;i<60;i++) input[i]=0; } else{ input[n]=128; for(i=n+1;i<60;i++) input[i]=0; } } creat_w(input,w); /*for(i=0;i<80;i++) printf("%lx,",w[i]);*/ printf("\n"); A=H0;B=H1;C=H2;D=H3;E=H4; for(i=1;i < 80;i++){ flag=i/20; switch(flag){ case 0: k=0x5a827999;f=(B&C)|(~B&D);break; case 1: k=0x6ed9eba1;f=B^C^D;break; case 2: k=0x8f1bbcdc;f=(B&C)|(B&D)|(C&D);break; case 3: k=0xca62c1d6;f=B^C^D;break; } /*printf("%lx,%lx\n",k,f); */ temp1=A<<5; temp2=A>>27; temp3=temp1|temp2; temp=temp3+f+E+w[i]+k; E=D; D=C; temp1=B<<30; temp2=B>>2; C=temp1|temp2; B=A; A=temp; printf("第%d步:",i+1); printf("A = %lx,B = %lx,C = %lx,D = %lx,E = %lx\n",A,B,C,D,E); } H0=H0+A; H1=H1+B; H2=H2+C; H3=H3+D; H4=H4+E; printf("\n哈希值:\n"); printf("%lx%lx%lx%lx%lx\n",H0,H1,H2,H3,H4); system("pause"); }写出这段代码每一行的意思
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值