示例#1
0
 /// <summary>
 /// 添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/2</para>
 /// </remarks>
 public void Add(string key, object value)
 {
     WebCache.Add(GetKeySuffix(key), value, this.DefaultExpireTime);
 }
示例#2
0
 /// <summary>
 /// 删除所有缓存
 /// </summary>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void RemoveAll()
 {
     WebCache.RemoveAll();
 }
示例#3
0
 /// <summary>
 /// 根据正则表达式模糊匹配删除缓存
 /// </summary>
 /// <param name="pattern">正则表达式</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void RemoveByPattern(string pattern)
 {
     WebCache.RemoveByPattern(pattern);
 }
示例#4
0
 /// <summary>
 /// 根据KEY键删除缓存
 /// </summary>
 /// <param name="key">KEY键</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void Remove(string key)
 {
     WebCache.Remove(key);
 }
示例#5
0
 /// <summary>
 /// 根据KEY异步删除缓存
 /// </summary>
 /// <param name="key">KEY键</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void RemoveAsync(string key)
 {
     Task.Run(() => WebCache.Remove(GetKeySuffix(key)));
 }
示例#6
0
 /// <summary>
 /// 异步添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="timeSpan">配置时间间隔</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void AddAsync(string key, object value, TimeSpan timeSpan)
 {
     Task.Run(
         () =>
         WebCache.Add(GetKeySuffix(key), value, null, Cache.NoAbsoluteExpiration, timeSpan, CacheItemPriority.Normal, null));
 }
示例#7
0
 /// <summary>
 /// 根据KEY键获取转化成指定的对象,指示获取转化是否成功的返回值
 /// </summary>
 /// <param name="key">KEY键</param>
 /// <param name="obj">需要转化返回的对象</param>
 /// <returns>是否成功</returns>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/2</para>
 /// </remarks>
 public bool GetCacheTryParse(string key, out object obj)
 {
     return(WebCache.GetCacheTryParse(GetKeySuffix(key), out obj));
 }
示例#8
0
 /// <summary>
 /// 根据KEY键获取返回对象
 /// </summary>
 /// <param name="key">键</param>
 /// <returns>返回对象</returns>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public object Get(string key)
 {
     return(WebCache.Get(GetKeySuffix(key)));
 }
示例#9
0
 /// <summary>
 /// 根据KEY键获取返回指定的类型对象
 /// </summary>
 /// <typeparam name="T">返回类型</typeparam>
 /// <param name="key">KEY值</param>
 /// <returns>需要返回的对象</returns>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public T Get <T>(string key)
 {
     return(WebCache.Get <T>(GetKeySuffix(key)));
 }
示例#10
0
 /// <summary>
 /// 添加K/V集合
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="items"> 键/值对的泛型集合。</param>
 /// <param name="dependencies">该项的文件依赖项或缓存键依赖项。 当任何依赖项更改时,该对象即无效,并从缓存中移除。 如果没有依赖项,则此参数包含 null。</param>
 /// <param name="absoluteExpiration">所添加对象将到期并被从缓存中移除的时间。</param>
 /// <param name="slidingExpiration"> 最后一次访问所添加对象时与该对象到期时之间的时间间隔。 如果该值等效于 20 分钟,则对象在最后一次被访问 20 分钟之后将到期并从缓存中移除。   如果使用绝对到期,则 slidingExpiration 参数必须为 System.Web.Caching.Cache.NoSlidingExpiration。</param>
 /// <param name="priority">对象的相对成本,由 System.Web.Caching.CacheItemPriority 枚举表示。 缓存在退出对象时使用该值;具有较低成本的对象在具有较高成本的对象之前被从缓存移除。</param>
 /// <param name="callback"> 在从缓存中移除对象时所调用的委托(如果提供)。 当从缓存中删除应用程序的对象时,可使用它来通知应用程序。</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void Add <T>(IDictionary <string, T> items, CacheDependency dependencies, DateTime absoluteExpiration,
                     TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback callback)
 {
     WebCache.Add <T>(items, dependencies, absoluteExpiration, slidingExpiration, priority, callback);
 }
示例#11
0
 /// <summary>
 /// 添加K/V集合
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="items"> 键/值对的泛型集合。</param>
 /// <param name="dependencies">该项的文件依赖项或缓存键依赖项。 当任何依赖项更改时,该对象即无效,并从缓存中移除。 如果没有依赖项,则此参数包含 null。</param>
 /// <param name="absoluteExpiration">所添加对象将到期并被从缓存中移除的时间。</param>
 /// <param name="slidingExpiration"> 最后一次访问所添加对象时与该对象到期时之间的时间间隔。 如果该值等效于 20 分钟,则对象在最后一次被访问 20 分钟之后将到期并从缓存中移除。   如果使用绝对到期,则 slidingExpiration 参数必须为 System.Web.Caching.Cache.NoSlidingExpiration。</param>
 /// <param name="priority">对象的相对成本,由 System.Web.Caching.CacheItemPriority 枚举表示。 缓存在退出对象时使用该值;具有较低成本的对象在具有较高成本的对象之前被从缓存移除。</param>
 /// <param name="callback"> 在从缓存中移除对象时所调用的委托(如果提供)。 当从缓存中删除应用程序的对象时,可使用它来通知应用程序。</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration,
                 TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback callback)
 {
     WebCache.Add(GetKeySuffix(key), value, dependencies, absoluteExpiration, slidingExpiration, priority, callback);
 }
示例#12
0
 /// <summary>
 /// 添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="expires">失效时间</param>
 /// <param name="flag">缓存是否永不过期</param>
 /// <param name="priority">指定 System.Web.Caching.Cache 对象中存储的项的相对优先级。</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void Add(string key, object value, long expires, bool flag, CacheItemPriority priority)
 {
     WebCache.Add(GetKeySuffix(key), value, expires, flag, priority);
 }
示例#13
0
 /// <summary>
 /// 异步添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="numOfMinutes">失效时间</param>
 /// <param name="flag">缓存是否永不过期</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void AddAsync(string key, object value, long numOfMinutes, bool flag)
 {
     Task.Run(() => WebCache.Add(GetKeySuffix(key), value, numOfMinutes, flag));
 }
示例#14
0
 /// <summary>
 /// 添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="numOfMinutes">失效时间</param>
 /// <param name="flag">缓存是否永不过期</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void Add(string key, object value, long numOfMinutes, bool flag)
 {
     WebCache.Add(GetKeySuffix(key), value, numOfMinutes, flag);
 }
示例#15
0
 /// <summary>
 /// 异步添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/2</para>
 /// </remarks>
 public void AddAsync(string key, object value)
 {
     Task.Run(() => WebCache.Add(GetKeySuffix(key), value, DefaultExpireTime));
 }
示例#16
0
        /// <summary>
        /// 根据KEY键异步获取返回指定的类型对象
        /// </summary>
        /// <typeparam name="T">返回类型</typeparam>
        /// <param name="key">KEY值</param>
        /// <returns>需要返回的对象</returns>
        /// <remarks>
        ///     <para>创建:范亮</para>
        ///     <para>日期:2016/4/5</para>
        /// </remarks>
        public async Task <T> GetAsync <T>(string key)
        {
            var result = await Task.Run(() => WebCache.Get <T>(GetKeySuffix(key)));

            return(result);
        }
示例#17
0
 /// <summary>
 /// 添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="flag">缓存是否永不过期</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/2</para>
 /// </remarks>
 public void Add(string key, object value, bool flag)
 {
     WebCache.Add(GetKeySuffix(key), value, flag);
 }
示例#18
0
 /// <summary>
 /// 添加K/V本地缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="numOfMinutes">失效时间</param>
 /// <remarks>
 ///     <para>创建:范亮</para>
 ///     <para>日期:2016/4/5</para>
 /// </remarks>
 public void Add(string key, object value, long numOfMinutes)
 {
     WebCache.Add(GetKeySuffix(key), value, null, DateTime.Now.AddMinutes((double)numOfMinutes), Cache.NoSlidingExpiration,
                  CacheItemPriority.High, null);
 }