public static void Permanent(string key, object obj, CacheDependency dep)
{
if (obj != null)
{
_cache.Insert(key, obj, dep, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
}
}
public static object Get(string key)
{
return _cache[key];
}
/// <summary>
/// Return int of seconds * SecondFactor
/// </summary>
public static int SecondFactorCalculate(int seconds)
{
// Insert method below takes integer seconds, so we have to round any fractional values
return Convert.ToInt(Math.Round((double)seconds * SecondFactor));
}
}
}
其实这个类就是一个单件模式的设计 和缓存的公共操作方法,其中CacheDependency表示建立缓存依赖项,CacheItemPriority表示缓存的优先级。S使用如下
复制代码 代码如下:
public static CardShop.Model.Systems GetConfig()
{
const string cacheKey = "WebConfig";
CardShop.Model.Systems sampleCacheTable = Larry.Cache.BaseCache.Get(cacheKey) as CardShop.Model.Systems;
if (sampleCacheTable == null)
{
OprationCheck.Message("第一次加载使用缓存");
sampleCacheTable = model;
Larry.Cache.BaseCache.Insert(cacheKey, sampleCacheTable, 24 * Larry.Cache.BaseCache.MinuteFactor);
}
else
{
OprationCheck.Message("已经加载了缓存不需要再加载");
}
return sampleCacheTable;
}