ASP.NET Cache»º´æÏê½â
Àý×Ó£º
using system.web.caching
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
DataView Source;
// Retrieve the DataView object from Cache. If not exist, then add DataView object to the Cache.
Source = (DataView)Cache["MyDataSet"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("Server=ServerName; database=Pubs; user id=UID; password=PWD;");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyDataSet"] = Source;
CacheMsg.Text = "Dataset created explicitly";
}
else {
CacheMsg.Text = "Dataset retrieved from cache";
}
// Binding the DataView object with DataGrid.
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
}
</script>
<body>
<form method="GET" runat="server">
<h3><font face="Verdana">Caching Data</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaad" />
<p>
<i><asp:label id="CacheMsg" runat="server"/></i>
</form>
</body>
</html>
ASP.NET CacheÊÇÌáÉýϵͳÐÔÄܵÄÖØÒª·½·¨£¬ËüʹÓÃÁË“×î½üʹÓÔÔÔò£¨a least-recently-used algorithm£©¡£ÔÚÊý¾Ý¿â·ÃÎÊÖо³£»áÓõ½Cache±£´æÊý¾Ý¿âÊý¾Ý¡£ 1.»º´æµÄÌí¼Ó£ºCacheµÄÌí¼Ó·½·¨ÓÐAdd()»òInsert£¨£©£¬Á½ÖÖ·½·¨¼¸ºõÀàËÆ£¬Ö»ÊÇInser·½·¨¿ÉÒÔʹÓÿÉÑ¡²ÎÊý£¬¼´Ê¹ÓÃĬÈϲÎÊý£¬À´ÊµÏÖ»º´æµÄÌ
Ïà¹ØÎĵµ£º
Ê×Ò³£º
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head ......
ASP.NetÓʼþ·¢ËÍÀà
±¾ÎÄת×Ô£ºhttp://www.pcstu.com/program/Asp_net/sl/20070706/52523.html
˵Ã÷£º±¾ÎÄûÓвâÊÔ£¬µ«¿´ÆðÀ´Ëƺõ²»ÄÜÓÃÓÚ·¢Ë͸½¼þ£¬ÈçÒª·¢Ë͸½¼þ£¬¿É²Î¿¼£ºhttp://blog.csdn.net/lff642/archive/2008/07/15/2654346.aspx
using System;
using System.Text;
using System.IO;
using System.Net;
using ......
Asp.netÖ§³ÖÈýÖÖÀàÐ͵Äcache
Ïëдһ¸ö¼¼Êõ¿ìËÙ¸ÅÊö£¬¿ÉÄÜдµÃÌ«¶àÁË¡£¼¼Êõ¸ÅÂÔµÄÄ¿µÄÊÇÒÔ×î¿ì×î¼òµ¥µÄ·½Ê½ÃèÊö³ö¼¼ÊõÒªµã£¬Ò²ÊÇÎÒÏ£ÍûµÄ×îÓÐЧÂʵÄ֪ʶ´«²¥·½Ê½¡£
1£® Ò³Ãæ/¿Ø¼þcache
2£® Ó¦ÓóÌÐò¼¶cache
3£® ä¯ÀÀÆ÷¿Í»§¶Ëcache
´ÓʵÏÖ·½Ê½À´¿´£¬Ò³Ãæ/¿Ø¼þcacheºÍÓ¦ÓóÌÐò¼¶cache¶¼ÊÇ´æ·ÅÔÚ·þÎñÆ÷ÄÚ´æÀïÃæµÄ£¬Ëæ×ÅÄÚ ......
ʹÓÃDataRelationÀà´´½¨¹ØÏµ²¢ÀûÓø¸/×Ó¹ØÏµ¶ÁÈ¡Êý¾ÝʾÀý
void Page_Load(object sender, System.EventArgs e)
{
// Á¬½Ó×Ö·û´®ºÍ SQL Óï¾ä
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
......