/// <summary> /// 设置缓存数据 /// </summary> /// <param name="key">缓存key</param> /// <param name="data">数据</param> /// <param name="CacheTime">时间</param> /// <param name="Cachetype">1-天为单位,2小时为单位,3-分钟为单位4-指定时间</param> /// <param name="ExpiredTime">指定时间</param> public static void SetCache(string key, string data, int CacheTime, int Cachetype, DateTime ExpiredTime) { string poolName = "POOL"; if (Cachetype != 4) { CacheMethod.SetMemValues(poolName, key, data, CacheTime, Cachetype); } else { CacheMethod.SetMemValuesExpiredTime(poolName, key, data, ExpiredTime); } }
/// <summary> /// 获取缓存数据 /// </summary> /// <param name="Key">缓存key</param> /// <returns></returns> public static string GetCache(string Key) { string data = string.Empty; try { object po = CacheMethod.GetMemCacheValues("POOL", Key); if (po != null && !string.IsNullOrEmpty(po.ToString())) { data = po.ToString(); } } catch { } return(data); }
/// <summary> /// 设置缓存数据 /// </summary> /// <param name="poolName">缓存池名</param> /// <param name="PerKey">缓存key</param> /// <param name="Data">数据</param> /// <param name="CM">配置对象</param> public static void SetCache(string poolName, string PerKey, string Data, CacheModel CM) { if (CM != null) { if (CM.Cachetype != 4) { CacheMethod.SetMemValues(poolName, PerKey, Data, CM.CacheTime, CM.Cachetype); } else { CacheMethod.SetMemValuesExpiredTime(poolName, PerKey, Data, CM.ExpiredTime); } } else { CacheMethod.setMemcachedValue(poolName, PerKey, Data); } }
/// <summary> /// 向缓存池存入值,数据缓存指定时间 /// 默认缓存1天 /// </summary> /// <param name="poolName">缓存池名</param> /// <param name="key">缓存键</param> /// <param name="value">缓存内容</param> /// <param name="cacheTime">缓存时间值</param> /// <param name="cacheType">1-天为单位,2小时为单位,3-分钟为单位</param> /// <returns></returns> public static bool SetMemValues(string poolName, string key, string value, int cacheTime, int cacheType) { DateTime d1 = DateTime.Now.AddDays(1.0); switch (cacheType) { case 1: d1 = DateTime.Now.AddDays((double)cacheTime); break; case 2: d1 = DateTime.Now.AddHours((double)cacheTime); break; case 3: d1 = DateTime.Now.AddMinutes((double)cacheTime); break; } return(CacheMethod.setMemCacheValues(poolName, key, value, d1)); }
/// <summary> /// 向缓存池存入值,数据缓存指定时间 /// </summary> /// <param name="poolName">缓存池名</param> /// <param name="key">缓存键</param> /// <param name="value">缓存内容</param> /// <param name="ExpiredTime">失效时间</param> /// <returns></returns> public static bool SetMemValuesExpiredTime(string poolName, string key, string value, DateTime ExpiredTime) { return(CacheMethod.setMemCacheValues(poolName, key, value, ExpiredTime)); }
/// <summary> /// 向缓存池存入值,数据缓存默认分钟数 /// </summary> /// <param name="poolName">缓存池名</param> /// <param name="key">缓存键</param> /// <param name="value">缓存内容</param> /// <returns></returns> public static bool setMemcacheValueInMinutes(string poolName, string key, string value) { DateTime d1 = DateTime.Now.AddMinutes(double.Parse(CacheConfig.CacheMinutes)); return(CacheMethod.setMemCacheValues(poolName, key, value, d1)); }
/// <summary> /// 向缓存池存入值,数据缓存默认天数 /// </summary> /// <param name="poolName">缓存池名</param> /// <param name="key">缓存键</param> /// <param name="Value">缓存内容</param> /// <returns></returns> public static bool setMemcachedValue(string poolName, string key, string Value) { DateTime d1 = DateTime.Now.AddDays(double.Parse(CacheConfig.CacheDays)); return(CacheMethod.setMemCacheValues(poolName, key, Value, d1)); }