tailieunhanh - pro vb 2005 and the net 2.0 platform 2nd edition 2006 phần 10

ưu ý Nếu bạn muốn truy cập vào Cache từ bên trong , 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ừ , 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 STATE MANAGEMENT TECHNIQUES 933 Note If you wish to access the Cache from within you are required to use the Context property. However if you are within the scope of a 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 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 web application named CacheState and insert . Like an application-level variable maintained by the HttpApplicationState type the Cache may hold any 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 . Given these stats update your Global class type like so code analysis to follow @ Application Language VB @ Import Namespace @ Import Namespace script runat server Define a shared Cache .

TỪ KHÓA LIÊN QUAN