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);
}
}

 

你可能感兴趣的:(CacheManager)