/// <summary> /// 写入缓存 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <param name="value"></param> /// <param name="depFile"></param> /// <returns></returns> public bool Set <T>(string key, T value, string depFile) { key = CacheUtils.getPrefixKey(key); bool ret1 = db.StringSet(key, CacheUtils.ConvertJson(value)); if (ret1 && File.Exists(depFile)) { FileInfo fi = new FileInfo(depFile); DateTime lastWriteTime = fi.LastWriteTime; return(db.StringSet(key + "_time", CacheUtils.ConvertJson(lastWriteTime))); } return(false); }
/// <summary> /// 写入缓存 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <param name="value"></param> /// <param name="timeSpan"></param> /// <returns></returns> public bool Set <T>(string key, T value, TimeSpan timeSpan) { key = CacheUtils.getPrefixKey(key); return(db.StringSet(key, CacheUtils.ConvertJson(value), timeSpan)); }
/// <summary> /// 写入缓存,设置过期秒数 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="key">缓存key</param> /// <param name="value">缓存值</param> /// <param name="expiresSecond">过期秒数</param> /// <returns>返回值,表示:是否写入成功</returns> public bool Set <T>(string key, T value, int expiresSecond) { key = CacheUtils.getPrefixKey(key); return(db.StringSet(key, CacheUtils.ConvertJson(value), DateTime.Now.AddSeconds(expiresSecond) - new DateTime())); }
/// <summary> /// 写入缓存,设置过期时间点 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="key">缓存key</param> /// <param name="value">缓存值</param> /// <param name="expiresAt">过期时间点</param> /// <returns>返回值,表示:是否写入成功</returns> public bool Set <T>(string key, T value, DateTime expiresAt) { key = CacheUtils.getPrefixKey(key); return(db.StringSet(key, CacheUtils.ConvertJson(value), expiresAt - new DateTime())); }