ASP.NET -- WebForm -- 缓存Cache的使用
把数据从数据库或文件中读取出来,放在内存中,后面的用户直接从内存中取数据,速度快。适用于经常被查询、但不经常变动的数据。
1. Test5.aspx文件与Test5.aspx.cs文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test5.aspx.cs" Inherits="Test5" %> <!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 runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="LabelCurrentTime" runat="server" Text=""></asp:Label> <asp:Button ID="Button1" runat="server" Text="添加值至缓存" onclick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="移除缓存" onclick="Button2_Click" /><br /> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> </div> </form> </body> </html>