/// <summary> /// Adds the specified key and object to the cache. /// </summary> public virtual void Set(string key, object data, TimeSpan expire) { var res = new CacheResult <object>(data); var json = res.ToJson(); this._db.StringSet(key, (string)json, expire); }
/// <summary> /// Adds the specified key and object to the cache. /// </summary> public virtual void Set(string key, object data, TimeSpan expire) { var res = new CacheResult <object>() { Success = true, Result = data }; var entryBytes = this.Serialize(res); this._db.StringSet(key, entryBytes, expire); }
/// <summary> /// Adds the specified key and object to the cache. /// </summary> public virtual void Set(string key, object data, TimeSpan expire) { var policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTime.Now + expire; var res = new CacheResult <object>() { Result = data, Success = true }; Cache.Add(new CacheItem(key, Serialize(res)), policy); }
/// <summary> /// Adds the specified key and object to the cache. /// </summary> public virtual void Set(string key, object data, TimeSpan expire) { RedisManager.PrepareDataBase(_db => { var res = new CacheResult <object>() { Success = true, Result = data }; var entryBytes = this.Serialize(res); _db.StringSet(key, entryBytes, expire); return(true); }, CACHE_DB); }
/// <summary> /// Gets or sets the value associated with the specified key. /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="key">The key of the value to get.</param> /// <returns>The value associated with the specified key.</returns> public virtual CacheResult <T> Get <T>(string key) { var cache = new CacheResult <T>() { Success = false }; var bs = Cache[key] as byte[]; if (bs != null) { cache.Result = Deserialize <T>(bs); cache.Success = true; } return(cache); }
/// <summary> /// Gets or sets the value associated with the specified key. /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="key">The key of the value to get.</param> /// <returns>The value associated with the specified key.</returns> public virtual CacheResult <T> Get <T>(string key) { var cache = new CacheResult <T>() { Success = false }; RedisManager.PrepareDataBase(_db => { var rValue = _db.StringGet(key); if (rValue.HasValue) { cache.Result = Deserialize <T>(rValue); cache.Success = true; } return(true); }, CACHE_DB); return(cache); }
/// <summary> /// Gets or sets the value associated with the specified key. /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="key">The key of the value to get.</param> /// <returns>The value associated with the specified key.</returns> public virtual CacheResult <T> Get <T>(string key) { var cache = new CacheResult <T>() { Success = false }; var rValue = this._db.StringGet(key); if (rValue.HasValue) { var res = this.Deserialize <CacheResult <T> >(rValue); if (res != null) { res.Success = true; cache = res; } } return(cache); }
/// <summary> /// Gets or sets the value associated with the specified key. /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="key">The key of the value to get.</param> /// <returns>The value associated with the specified key.</returns> public virtual CacheResult <T> Get <T>(string key) { var cache = new CacheResult <T>() { Success = false }; var rValue = this._db.StringGet(key); if (rValue.HasValue) { var res = ((string)rValue).JsonToEntity <CacheResult <T> >(throwIfException: false); if (res != null) { res.Success = true; cache = res; } } return(cache); }
/// <summary> /// Gets or sets the value associated with the specified key. /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="key">The key of the value to get.</param> /// <returns>The value associated with the specified key.</returns> public virtual CacheResult <T> Get <T>(string key) { var cache = new CacheResult <T>() { Success = false }; RedisManager.PrepareDataBase(_db => { var rValue = _db.StringGet(key); if (rValue.HasValue) { var res = this.Deserialize <CacheResult <T> >(rValue); if (res != null) { res.Success = true; cache = res; } } return(true); }, CACHE_DB); return(cache); }
/// <summary> /// 设置数据,并标记为成功 /// </summary> public static void SetSuccessData <T>(this CacheResult <T> data, T model) { data.Success = true; data.Result = model; }
public static CacheResult <T> OK <T>(this CacheResult <T> data) { data.Success = true; return(data); }