using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
namespace Zhaizj.Framework.Caching {
///
/// .net 自带的 InMemory 缓存
///
public class SysCache {
///
/// 从缓存中获取值
///
///
///
public static Object Get( String key ) {
return HttpRuntime.Cache[key];
}
///
/// 将对象放入缓存,如果缓存中已有此项,则替换。a)永不过期,b)优先级为 Normal,c)没有缓存依赖项
///
///
///
public static void Put( String key, Object val ) {
HttpRuntime.Cache[key] = val;
}
///
/// 将对象放入缓存,在参数 seconds 指定的秒数之后过期
///
///
///
///
public static void Put( String key, Object val, int seconds ) {
HttpRuntime.Cache.Insert( key, val, null, DateTime.UtcNow.AddSeconds( (double)seconds ), Cache.NoSlidingExpiration );
}
///
/// 将对象放入缓存,在最后一次访问之后的 seconds 秒数之后过期(弹性过期)
///
///
///
///
public static void PutSliding( String key, Object val, int seconds ) {
HttpRuntime.Cache.Insert( key, val, null, Cache.NoAbsoluteExpiration, new TimeSpan( 0, 0, seconds ) );
}
///
/// 从缓存中移除某项
///
///
public static void Remove( String key ) {
if (strUtil.HasText( key )) {
HttpRuntime.Cache.Remove( key );
}
}
}
}