Cache technology in .NET (1)

xiaoxiao2021-03-06  88

Cache technology in .NET: Cache is a technology widely used in computing to improve performance, which stores data from high access frequencies or data high-high data in memory. In web development, performance is an important factor in the quality of the application, and the cache is greatly helpful to improve performance. Let's take a look at the problem that the cache can solve: 1. Performance - stores the corresponding data to avoid repeated creation, processing, and transmission of data, and effectively improve performance. For example, the data that does not change will be cached, such as a national list, etc., which can significantly improve the reaction speed of the web program; 2. In the same application, often the same data, logic function, and user interface multiple requests frequently occurring. When the number of users is large, if each request is processed, the consumed resource is a lot of waste, and it also causes the system to instability. 3. Availability - Sometimes the service providing data information may stop unexpectedly, and if the cache technology is used, the support of the end user can be provided in a certain period of time, and the availability of the system can be improved.

Then let's take a look at the cache in ASP.NET: 1. In ASP.NET, the Cache object specifically designed to cache data is provided, and its application range is the application domain. The survival period is closely related to the application, and whenever the application is started, recreate the Cache object. It is the main difference between Application objects to provide features, such as dependence, and expiration strategies specifically for cache management. 2.Cache Object Defines in System.Web.Caching Namespace, you can use the cache attribute of the HTTPContext class or the cache property of the Page object to get the cache reference, in addition to the storage key value, you can store the object of the .NET framework. .

The cache is saved in memory for the next call, but after the data is updated, the data in the memory is not updated, and it is still the previous data. How do you update the cache data? We use dependent and expiration strategies. There are three ways to implement: 1. File dependency 2. Key Dependency 3. Time-based expired policy

First let's see the documentation. The file dependence is to force the cache data when certain (certain) file changes on the hard disk. Example: cachedependency dep = new cachedependency (Server.MAppath ("file.xml")); cache.insert ("key", "value", dep);

Note: The file-dependent is added by using cache.insert and providing a cachedependency object that references an XML file.

转载请注明原文地址:https://www.9cbs.com/read-123242.html

New Post(0)