c# cache 缓存
System.Web.Caching简介
/// <summary>
/// 创建随机字符串
/// </summary>
/// <returns></returns>
public static string CreatenNonce_str()
{
var cache = HttpContext.Current.Cache;
var cacheCreatenNonceStr = cache.Get("cacheCreatenNonce_str");
if (cacheCreatenNonceStr==null)
{
Random r = new Random();
var sb = new StringBuilder();
var length = strs.Length;
for (int i = 0; i < 15; i++)
{
sb.Append(strs[r.Next(length - 1)]);
}
//如果缓存不存在,则添加——保存时间是7000秒
cache.Add("cacheCreatenNonce_str", sb, null, DateTime.Now.AddSeconds(7000), TimeSpan.Zero, CacheItemPriority.Normal, null);
return sb.ToString();
}
return cacheCreatenNonceStr.ToString();
}