/// <summary> /// 向缓存中添加一个缓存项。 /// </summary> /// <param name="key">表示一个缓存的键。</param> /// <param name="value">表示一个缓存的值。</param> /// <param name="policy">缓存使用的策略(一般是过期策略)</param> /// <param name="region">表示缓存所属的域。</param> /// <returns>添加成功返回 true, 失败返回 false。</returns> public bool Add(string key, object value, Policy policy, string region = null) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException($"parameter {nameof(key)} can not be null or empty."); } if (!this.IsEnabled) { return(false); } if (value == null) { return(false); } ChangeChecker checker = null; if (policy != null) { checker = policy.Checker; } return(this.AddCore(region, key, new StoredValue() { Value = value, Checker = checker })); }
/// <summary> /// 添加一个新的检测器 /// </summary> /// <param name="item"></param> public void Add(ChangeChecker item) { for (int i = 0, c = this._checkers.Count; i < c; i++) { var checker = this._checkers[i]; if (checker.Equals(item)) return; } this._checkers.Add(item); }
/// <summary> /// 向缓存中添加一项。 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="policy">缓存使用的策略(一般是过期策略)</param> /// <param name="region"></param> /// <returns></returns> public bool Add(string key, object value, Policy policy, string region = null) { if (value == null) { return(false); } ChangeChecker checker = null; if (policy != null) { checker = policy.Checker; } return(this.AddCore(region, key, new StoredValue() { Value = value, Checker = checker })); }