Đang chuẩn bị liên kết để tải về tài liệu:
pro vb 2005 and the net 2.0 platform 2nd edition 2006 phần 10

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

ưu ý Nếu bạn muốn truy cập vào Cache từ bên trong Global.asax, bạn được yêu cầu sử dụng tài sản ngữ cảnh. Tuy nhiên, nếu bạn đang trong phạm vi của một loại có nguồn gốc từ System.Web.UI.Page, bạn có thể làm cho việc sử dụng của các đối tượng Cache trực tiếp. | CHAPTER 27 ASP.NET 2.0 STATE MANAGEMENT TECHNIQUES 933 Note If you wish to access the Cache from within Global.asax you are required to use the Context property. However if you are within the scope of a System.Web.UI.Page-derived type you can make use of the Cache object directly. Now understand that if you have no interest in automatically updating or removing an application-level data point as seen here the Cache object is of little benefit as you can directly use the HttpApplicationState type. However when you do wish to have a data point destroyed after a fixed point of time and optionally be informed when this occurs the Cache type is extremely helpful. The System.Web.Caching.Cache class defines only a small number of members beyond the type s indexer. For example the Add method can be used to insert a new item into the cache that is not currently defined if the specified item is already present Add does nothing . The Insert method will also place a member into the cache. If however the item is currently defined Insert will replace the current item with the new type. Given that this is most often the behavior you will desire I ll focus on the Insert method exclusively. Fun with Data Caching Let s see an example. To begin create a new ASP.NET web application named CacheState and insert aGlobal.asaxfile. Like an application-level variable maintained by the HttpApplicationState type the Cache may hold any System.Object-derived type and is often populated within the Application_ Start event handler. For this example the goal is to automatically update the contents of a DataSet every 15 seconds. The DataSet in question will contain the current set of records from the Inventory table of the Cars database created during our discussion of ADO.NET. Given these stats update your Global class type like so code analysis to follow @ Application Language VB @ Import Namespace System.Data.SqlClient @ Import Namespace System.Data script runat server Define a shared Cache .