ASP.Net Cache(缓存)
来源:互联网 发布:淘宝运费险咨询电话 编辑:程序博客网 时间:2024/05/01 05:05
实验目的:
把数据放到Cache中,在指定的时间内,可以直接从Cache中获取,避免对数据库等的压力。
案例:人员列表的缓存
(*)页面缓存、数据库源缓存。。。
(*)memcached
代码
Cache.html
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cache.aspx.cs" Inherits="wj.Cache" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title></head><body> <form id="form1" runat="server"> <div> 用户信息: <ul> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate><li>姓名:<%#Eval("username") %>密码:<%#Eval("password") %></li></ItemTemplate> </asp:Repeater> </ul> </div> </form></body></html>
Cache.cs
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace wj{ public partial class Cache : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //人员信息展示 /* DataTable tt= SqlHelper.ExecuteQuery("select * from T_users"); */ //缓存,使得查询过的数据先保存在内存中 //1.数据查询来了。好。先去缓存中查找 DataTable tt = (DataTable)HttpRuntime.Cache["persons"]; if (tt == null)//如果缓存Catche中没有,再去数据库中查询,,这样可以降低数据库服务器的压力 { tt = SqlHelper.ExecuteQuery("select * from T_users"); //将查询的结果存入缓存中,设置30秒后过期 HttpRuntime.Cache.Insert("persons", tt, null, DateTime.Now.AddSeconds(30), TimeSpan.Zero); } Repeater1.DataSource = tt; Repeater1.DataBind(); } }}
调试
调试打开,cache.aspx,在30秒之内,点击刷新按钮,调试查看后,tt已经有了缓存信息;
刷新页面后。
0 0
- ASP.Net Cache(缓存)
- ASP.NET--CACHE缓存
- ASP.NET Cache缓存
- ASP.NET 缓存(Cache)
- ASP.NET Cache缓存
- ASP.NET缓存 Cache
- ASP.NET 缓存(Cache)介绍
- ASP.NET 缓存(Cache)介绍
- ASP.NET 缓存(Cache)介绍
- ASP.NET 缓存(Cache)介绍
- ASP.NET——缓存(cache)
- Cache缓存 (asp.net c#)
- ASP.NET Cache缓存详解
- Asp.Net之Cache缓存
- ASP.NET缓存 Cache之数据缓存
- ASP.NET 缓存:方法和最佳实践 (cache)
- asp.net(c#)缓存Cache对象(学习日记一)
- ASP.NET状态管理之六(缓存Cache)
- ios学习7_iPhone屏幕尺寸、分辨率及适配
- scrollViewDidEndDecelerating方法不执行解决方案
- 将字符串转换成整数
- NLTK——NLP编程的基础工具
- 对象调用数组运用 学习很吃力
- ASP.Net Cache(缓存)
- Mybatis中的resultType和resultMap
- 二叉树的相关操作:创建、查找、求高度和深度、各种遍历(前、中、后、层序)等等
- 超级台阶
- order by 与group by的区别!
- 《C语言及程序设计》程序阅读——文件操作
- 关于学习资源的整合网站(想自学的可以看一下)
- Android PopupWindow的使用和分析
- 2. Zend_Controller 快速入门