c# 将数据写入缓存的问题

来源:百度知道 编辑:UC知道 时间:2024/04/29 19:15:00
我想将一些数据写入缓存当中,比如对象的类型,查询的结果等,怎么写呢?

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];
}

}
}

用我这个类就可以了,比楼上的封装性更好