第1个回答 2008-09-02
using System;
using System.Web;
using System.Web.Caching;
using System.Data;
using System.Collections.Generic;
using System.Text;
namespace Common
{
/// <summary>
/// 网站碎片缓存处理类
/// </summary>
public class WebCache
{
/// <summary>
/// 网站碎片缓存处理类
/// </summary>
/// <param name="key">Cache对象的键名</param>
public WebCache(string key) { this.KeyName = key; }
private string KeyName = "";
private Cache c = new Cache();
public void SetCache(object obj, int Seconds)
{
c.Insert(this.KeyName, obj, null, DateTime.Now.AddSeconds(Seconds), TimeSpan.Zero);
}
public object GetCache()
{
return c[this.KeyName];
}
}
}
用我这个类就可以了,比楼上的封装性更好本回答被提问者采纳