/// <summary> /// 设置缓存 /// </summary> /// <param name="key">key</param> /// <param name="value">值</param> /// <param name="type">数据类型</param> /// <param name="absoluteExpiration">绝对过期实现</param> /// <returns></returns> public bool Set(string key, object value, Type type, DateTime absoluteExpiration) { if (string.IsNullOrWhiteSpace(key) || value == null) { return(false); } _cache.Set(key, FastConvertHelper.Clone(value, type), new DateTimeOffset(absoluteExpiration)); return(true); }
/// <summary> /// 处理附加参数,给占位符填充值 /// </summary> /// <param name="source">原始字符串</param> /// <param name="keyArray">附加的参数名称数组</param> /// <param name="pars">参数字段</param> /// <param name="cacheKey">参数缓存Key</param> /// <returns></returns> private static string FillParamValues(string source, List <string> keyArray, Dictionary <string, object> pars, string cacheKey) { if (keyArray == null || keyArray.Count <= 0) { return(source); } foreach (var key in keyArray) { //参数包含: if (key.Contains(":")) { var arr = key.Split(':'); var keyFirst = arr[0]; var keySecond = arr[1]; if (!pars.TryGetValue(keyFirst, out object v)) { throw new Exception($"--AopCache {cacheKey} " + $"不包含参数 {keyFirst}"); } //var ob = JObject.FromObject(v); var ob = FastConvertHelper.ToDictionary(v); if (!ob.TryGetValue(keySecond, out object tokenValue)) { throw new Exception($"--AopCache {cacheKey} " + $"不包含参数 {keySecond}"); } source = source.Replace("{" + key + "}", tokenValue.ToString()); } else { if (!pars.TryGetValue(key, out object value)) { throw new Exception($"--AopCache {cacheKey} " + $"不包含参数 {key}"); } source = source.Replace("{" + key + "}", value.ToString()); } } return(source); }