using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBHelper;
using System.Data;
using MySql.Data.MySqlClient;
using System.Web.Caching; public partial class 缓存过期 : System.Web.UI.Page
{
static bool itemremove = false;
static CacheItemRemovedReason reson;
CacheItemRemovedCallback onremove = null; public void removeCallback(string k, object v, CacheItemRemovedReason r) { itemremove = true;
reson = r;
}
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = (DataSet)Cache["students"];
if (ds == null) {
ds = GetStudent();
onremove=new CacheItemRemovedCallback(this.removeCallback);
CacheDependency cd=new CacheDependency(Server.MapPath("web.config"));
Cache.Insert("students", ds, cd, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1), CacheItemPriority.High, onremove); }
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Cache["students"] != null) {
Cache.Remove("students"); }
if (itemremove)
{ Label1.Text += "REmove触发";
Label1.Text += "<br>";
Label1.Text += reson.ToString();
}
else {
Label1.Text += Server.HtmlEncode(Cache["students"] as string); }
} public static void SetCache(string CacheKey, object objObject, System.Web.Caching.CacheDependency dep)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(
CacheKey,
objObject,
dep,
System.Web.Caching.Cache.NoAbsoluteExpiration, //从不过期
System.Web.Caching.Cache.NoSlidingExpiration, //禁用可调过期
System.Web.Caching.CacheItemPriority.Default,
null);
} public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
} public DataSet GetStudent()
{
string sql = "select * from t_student";
return SqlHelper.ExecuteDataSetText(sql);
} }

  

最新文章

  1. HDU 1525 Euclid&#39;s Game 博弈
  2. 北邮oj 题
  3. C++/CLI——读书笔记《Visual C++/CLI从入门到精通》 第Ⅰ部分
  4. Word有用的快捷键
  5. Sqlserver_left join 、right join、 inner join 用法
  6. js获取ifram对象
  7. jquery事件切换hover/toggle
  8. Android开发代码规范
  9. codevs 1135 选择客栈
  10. bzoj 1853: [Scoi2010]幸运数字 容斥
  11. 启动php-fpm报错:please specify user and group other than root
  12. 提交svn报错说 有 unversioned 的文件
  13. 设计模式 --迭代器模式(Iterator)
  14. 数据库微信特殊表情编码django设置
  15. Windows之MySQL安装教程
  16. dlib编译成静态库及被其它程序调用
  17. Codeforces Codeforces Round #484 (Div. 2) E. Billiard
  18. Note of Python Turtle
  19. error: control may reach end of non-void function [-Werror,-Wreturn-type]
  20. React Native移动开发实战-3-实现页面间的数据传递

热门文章

  1. PHP while使用
  2. ActionListener的三种实现方法
  3. 转摘 MySQL扫盲篇
  4. Webservice服务创建、调用笔记
  5. Trace-语句启动Profiler中暂停的跟踪会出现什么状况
  6. app慢的可能情况需要优化
  7. 由LazyMan联想到的
  8. RDIFramework.NET ━ .NET快速信息化系统开发框架钜献 V3.0 版本强势发布
  9. git pull 冲突解决
  10. SSIS2012 项目部署模型