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>
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- 谈.Net委托与线程——创建无阻塞的异步调用(一
- winform下通过webclient使用非流方式上传(post)数据和
- MVC中一个表单实现多个提交按钮(一个action搞定
- 教你如何来恢复一个丢失的数据文件
- asp.net 六大内置对象(2)
- Pro ASP.NET MVC 3 Framework学习笔记之九
- Asp.net MVC源码分析--Model Validation(Client端)实现(2)
- 微软ASP.NET站点部署指南(11):部署SQL Server数据
- asp.net js模拟Button点击事件
- ASP.NET数据格式的Format--DataFormatString