MemCacheManager
#region Fields
private AreaRepository _areaRepository = new AreaRepository();
private ICacheManager _cacheManager = new MemCacheManager();
#endregion
public List<AreaInfo> GetAreaList(string clientNo)
{
//扩展与委托的使用
return _cacheManager.Get(
CacheSettings.AreaInfo.Get(clientNo), () =>
{
return _areaRepository.GetAreaList(clientNo);
});
}
//////////////////////扩展方法
public static T Get<T>(this ICacheManager cacheManager, CacheInfo cacheInfo, Func<T> acquire)
{
return cacheManager.Get<T>(cacheInfo.Key, cacheInfo.CacheTime, acquire);
}
///////////////////在Extensions.cs扩展
public static T Get<T>(this ICacheManager cacheManager, CacheInfo cacheInfo, Func<T> acquire)
{
return cacheManager.Get<T>(cacheInfo.Key, cacheInfo.CacheTime, acquire);
}
////////////////////cacheExtensions.cs中扩展
public static T Get<T>(this ICacheManager cacheManager, string key, int cacheTime, Func<T> acquire)
{
if (cacheManager.IsSet(key))
{
return cacheManager.Get<T>(key);
}
else
{
var result = acquire();
if (result != null)
cacheManager.Set(key, result, cacheTime);
return result;
}
}
/////////////////////////////////////////
public T Get<T>(string key)
{
if (Memcache.IsEnable)
{
try
{
return (T)memcached.Get(key);
}
catch (Exception ex)
{
ErrorLog.Write("MemCacheManager.Get<T>(" + key + ")", "[-9113]缓存服务_获取缓存项目发生异常", ex);
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。