ASP.NET自定义输出缓存提供程序(3)
public override object Get(string key)
{
string path =
String.Format("{0}{1}.binary", cachePath, key);
if (File.Exists(path))
{
FileStream fs = new FileStream(
path, FileMode.Open, FileAccess.Read);
BinaryFormatter formatter = new BinaryFormatter();
object result = formatter.Deserialize(fs);
fs.Close();
return result;
}
else
{
return null;
}
}
/// <summary>
/// 根据键移除缓存
/// </summary>
/// <param name="key">缓存键</param>
public override void Remove(string key)
{
string path =
String.Format("{0}{1}.binary", cachePath, key);
if (File.Exists(path))
{
File.Delete(path);
}
}
/// <summary>
/// 设置缓存
/// </summary>
/// <param name="key">缓存的键</param>
/// <param name="entry">缓存的对象</param>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>