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();
}

相关文章:

  • 2021-08-06
  • 2021-11-15
  • 2021-11-14
  • 2021-09-24
猜你喜欢
  • 2021-05-29
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2022-01-15
  • 2021-08-17
相关资源
相似解决方案