using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; using System.Web.Caching; namespace DYRebate { public class Comm { public static bool SetCache(string key, string value, int seconds = 180) { try { var MD5 = CsharpHttpHelper.HttpExtend.GetMD5String($"{key}"); Cache cache = HttpRuntime.Cache; //查找 md5 的缓存,不存在则返回null object item = cache[MD5]; if (item == null) cache.Insert(MD5, value, null, DateTime.Now.AddSeconds(seconds), System.Web.Caching.Cache.NoSlidingExpiration); return true; } catch (Exception ex) { } return false; } /// /// 获取缓存数据 /// /// /// /// /// public static string GetCache(string key) { try { var MD5 = CsharpHttpHelper.HttpExtend.GetMD5String($"{key}"); Cache cache = HttpRuntime.Cache; object item = cache[MD5]; return item?.ToString(); } catch (Exception) { } return null; } } }