.NET缓存类和说明
2012-04-05 09:00:38 来源:WEB开发网核心提示:/// <param name="jibie">缓存级别,级别高到低存放内存数据(NotRemovable = 6,.NET缓存类和说明(3),High = 5,AboveNormal = 4,Normal = 3,BelowNormal = 2,Low = 1)</param&g
/// <param name="jibie">缓存级别,级别高到低存放内存数据(NotRemovable = 6,High = 5,AboveNormal = 4,Normal = 3,BelowNormal = 2,Low = 1)</param>
public static void InsertSlidingCache(string CacheKey, object o, int expire,int jibie)
{
if (CacheKey == null || CacheKey.Length == 0 || o == null)
{
return;
}
CacheItemPriority dareje;
switch (jibie)
{
case 1: dareje = CacheItemPriority.Low; break;
case 2: dareje = CacheItemPriority.BelowNormal; break;
case 3: dareje = CacheItemPriority.Normal; break;
case 4: dareje = CacheItemPriority.AboveNormal; break;
case 5: dareje = CacheItemPriority.High; break;
case 6: dareje = CacheItemPriority.NotRemovable; break;
default: dareje = CacheItemPriority.Normal; break;
}
webCache.Insert(CacheKey, o, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(expire), dareje, null);
}
/********************************************绝对过期的缓存*****************************************************************/
/*
*
* 使用绝对过期的缓存的意思是在缓存创建后过了absoluteExpiration时间后缓存过期
* 用绝对过期的缓存slidingExpiration参数要设置TimeSpan.Zero,TimeSpan.Zero是0的意思
* 也就是说没时间偏差
* static Cache()
{
NoAbsoluteExpiration = DateTime.MaxValue;
NoSlidingExpiration = TimeSpan.Zero;
s_sentinelRemovedCallback = new CacheItemRemovedCallback(SentinelEntry.OnCacheItemRemovedCallback);
}
*/
// <summary>
/// 使用绝对过期的缓存中加入当前对象(过了expire时间后缓存过期)
/// </summary>
/// <param name="CacheKey">对象的键值</param>
/// <param name="o">缓存的对象</param>
/// <param name="expire">到期时间,单位:秒(0时最大的时间,高的级别,表示永不过期)</param>
/// <param name="jibie">缓存级别(NotRemovable = 6,High = 5,AboveNormal = 4,Normal = 3,BelowNormal = 2,Low = 1)</param>
public virtual void InsertAbsoluteCache(string CacheKey, object o, int expire,int jibie)
{
if (CacheKey == null || CacheKey.Length == 0 || o == null)
{
return;
}
CacheItemPriority dareje;
switch (jibie)
{
case 1: dareje = CacheItemPriority.Low; break;
case 2: dareje = CacheItemPriority.BelowNormal; break;
case 3: dareje = CacheItemPriority.Normal; break;
case 4: dareje = CacheItemPriority.AboveNormal; break;
case 5: dareje = CacheItemPriority.High; break;
case 6: dareje = CacheItemPriority.NotRemovable; break;
default:dareje = CacheItemPriority.Normal; break;
}
webCache.Insert(CacheKey, o, null, DateTime.Now.AddSeconds(expire), Cache.NoSlidingExpiration, dareje, null);
- ››缓存服务器在Linux下的应用
- ››Netpas加速 让非电信宽带用户流畅上网
- ››net中fckediter的图片上传时候点击\浏览服务器\出...
- ››Netmsg局域网聊天程序
- ››NetAirus指控苹果iPhone侵犯其专利
- ››Netflix 在线影视播放程序将登陆 iPhone
- ››Net中各种不同的对象创建方式的速度差异
- ››NetNewsWire 功能简单 界面快速 Reader 浏览器
- ››NET-使用Js调用WebService
- ››Net 应用程序如何在32位操作系统下申请超过2G的内...
- ››NET 4.0新特性-- Corrupted State Exceptions
- ››NET应用程序的本地化及RESGEN.exe, AL.exe介绍
更多精彩
赞助商链接