Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
 /// <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()));
 }
Exemplo n.º 4
0
 /// <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()));
 }