1. 程式人生 > >應用程序緩存

應用程序緩存

dbo ext ack tid click server int32 數據 nag

頁面:
<asp:Label ID="lblId" runat="server" Text="Label"></asp:Label>
<asp:Label ID="lblTitle" runat="server" Text="Label"></asp:Label>
<asp:Label ID="lblClick" runat="server" Text="Label"></asp:Label>


後臺:
if (!IsPostBack) {
int id = Convert.ToInt32(Request["id"]);
Books books = null;
if (Cache["Books_" + id] != null) {
//從內存中讀取
books = Cache["Books_" + id] as Books;
}
else
{
//請求數據庫
books = new BooksManager().getIdBooksInfo(id);

if (books!=null&&books.Clicks>200)
{
//添加應用程序緩存
Cache["Books_" + id] = books;
}
}
if (books!=null)
{
this.lblId.Text = Convert.ToString(books.Id);
this.lblTitle.Text = books.Title;
this.lblClick.Text = Convert.ToString(books.Clicks);
}


應用程序緩存