个人项目框架搭建
发布时间:2016-04-09 16:00:08
1、缓存接口using System;using System.Collections.Generic;using System.Runtime.Caching;using System.Text.RegularExpressions;namespace EnterpriseFr ...
1、缓存接口
using System;using System.Collections.Generic;using System.Runtime.Caching;using System.Text.RegularExpressions;namespace EnterpriseFrame.Core.Caching{ /// <summary> /// Represents a manager for caching between HTTP requests (long term caching) /// </summary> public partial class MemoryCacheManager : ICacheManager { protected ObjectCache Cache { get { return MemoryCache.Default; } } /// <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 T Get<T>(string key) { return (T)Cache[key]; } /// <summary> /// Adds the specified key and object to the cache. /// </summary> /// <param name="key">key</param> /// <param name="data">Data</param> /// <param name="cacheTime">Cache time</param> public virtual void Set(string key, object data, int cacheTime) { if (data == null) return; var policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTime.Now + TimeSpan.FromMinutes(cacheTime); Cache.Add(new CacheItem(key, data), policy); } /// <summary> /// Gets a value indicating whether the value associated with the specified key is cached /// </summary> /// <param name="key">key</param> /// <returns>Result</returns> public virtual bool IsSet(string key) { return (Cache.Contains(key)); } /// <summary> /// Removes the value with the specified key from the cache /// </summary> /// <param name="key">/key</param> public virtual void Remove(string key) { Cache.Remove(key); } /// <summary> /// Removes items by pattern /// </summary> /// <param name="pattern">pattern</param> public virtual void RemoveByPattern(string pattern) { var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); var keysToRemove = new List<String>(); foreach (var item in Cache) if (regex.IsMatch(item.Key)) keysToRemove.Add(item.Key); foreach (string key in keysToRemove) { Remove(key); } } /// <summary> /// Clear all cache data /// </summary> public virtual void Clear() { foreach (var item in Cache) Remove(item.Key); } }}
原标题:个人项目框架搭建
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。
波兰海外仓:https://www.goluckyvip.com/tag/4436.html
迅田国际:https://www.goluckyvip.com/tag/44360.html
迅田国际货运代理:https://www.goluckyvip.com/tag/44361.html
逊航跨境供应链:https://www.goluckyvip.com/tag/44362.html
逊捷精灵:https://www.goluckyvip.com/tag/44363.html
逊诉解封:https://www.goluckyvip.com/tag/44364.html
西安到都江堰旅游攻略有什么?:https://www.vstour.cn/a/407236.html
9月张家界有什么好玩的地方 张家界有几个好玩的地方:https://www.vstour.cn/a/407237.html