/// <summary> /// 获取缓存 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="key">键</param> /// <param name="acquireFactory">若缓存不存在则获取后在存储到缓存</param> /// <returns>值</returns> public static T Get <T>(string key, Func <T> acquireFactory) { WrapCacheConfigItem _cacheConfig = CacheConfigContext.GetCurrentWrapCacheConfigItem(key); ICacheProvider _cacheProvider = _cacheConfig.CacheProvider; if (_cacheProvider.IsSet(key)) { return(_cacheProvider.Get <T>(key)); } var _result = acquireFactory(); _cacheProvider.Set(key, _result, _cacheConfig.CacheConfigItem.Minitus, _cacheConfig.CacheConfigItem.IsAbsoluteExpiration); return(_result); }
/// <summary> /// 以键取值 /// </summary> /// <param name="key">键</param> /// <returns>值</returns> public static object Get(string key) { WrapCacheConfigItem _cacheConfig = CacheConfigContext.GetCurrentWrapCacheConfigItem(key); return(_cacheConfig.CacheProvider.Get(key)); }
/// <summary> /// 设置缓存 /// </summary> /// <param name="key">键</param> /// <param name="value">值</param> public static void Set(string key, object value) { WrapCacheConfigItem _cacheConfig = CacheConfigContext.GetCurrentWrapCacheConfigItem(key); _cacheConfig.CacheProvider.Set(key, value, _cacheConfig.CacheConfigItem.Minitus, _cacheConfig.CacheConfigItem.IsAbsoluteExpiration, null); }
/// <summary> /// 移除 /// </summary> /// <param name="key">键</param> public static void Remove(string key) { WrapCacheConfigItem _cacheConfig = CacheConfigContext.GetCurrentWrapCacheConfigItem(key); _cacheConfig.CacheProvider.Remove(key); }