.NET 缓存处理类

2014-11-27 0 898
.NET 缓存处理类
using System;
using System.Collections.Generic;
using System.Web.Caching;
using System.Web;

/// <summary>
/// This class reads/writes to ASP .NET server cache. For the sake of 
/// simplicity, the class writes objects to cache with no expirateion.
/// Use the Remove() function to programmatically remove objects stored
/// from the server cache. This class was created as an alternative  to 
/// storing large objects in the session.
/// </summary>
public class CacheHandler
{
	
	public static bool Write(string cacheID, object data)
	{
		if (HttpContext.Current == null)
			return false;

		if (cacheID == null || cacheID.Equals(""))
			return false;

		HttpRuntime.Cache.Insert(
				cacheID, data, null, Cache.NoAbsoluteExpiration, 
				Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null
				);
		return true;
	}

	public static object Read(string cacheID)
	{
		if (HttpContext.Current == null)
			return null;

		return HttpRuntime.Cache.Get(cacheID);
	}

	public static void Remove(string cacheID)
	{
		if (HttpContext.Current == null )
			return;

		if (cacheID == null || cacheID.Equals(""))
			return;

		HttpRuntime.Cache.Remove(cacheID);
	}
}

遇见资源网 ASP/Basic .NET 缓存处理类 http://www.ox520.com/13330.html

上一篇: VBS自动配置脚本
下一篇: ASP 获取JSON的值
常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务