In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about the concept of ASP.NET caching and its application process, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.
What is the concept of ASP.NET caching? In general, applications can improve performance by storing frequently accessed data, as well as data that requires a lot of processing time to create. For example, if your application uses complex logic to process large amounts of data, and then returns the data as reports that users access frequently, avoiding recreating the report each time the user requests data can be more efficient. Similarly, if your application contains a page that processes complex data but does not need to be updated frequently, it is inefficient for the server to recreate the page on each request.
In these cases, after understanding the concept of ASP.NET caching, to help you improve the performance of your application, ASP.NET caching uses two basic caching mechanisms to provide caching capabilities. The * mechanism is application caching, which allows you to cache generated data, such as DataSet or custom report business objects. The second mechanism is the page output cache, which saves the page processing output and reuses the saved output when the user requests the page again, rather than processing the page again.
ASP.NET caching application
Application caching provides a programmatic way to store arbitrary data in memory through key / value pairs. Using application caching is similar to using application state. However, unlike the application state, the data in the application cache is volatile, that is, the data is not stored in memory throughout the application life cycle. The advantage of using application caching is that ASP.NET manages the cache, which removes items from the cache when they expire, are invalid, or run out of memory. You can also configure the application cache to notify the application when items are removed. For more information, see caching Application data.
The mode of using the application cache is to determine whether an item exists in the cache when it is accessed, and if so, use it. If the item does not exist, you can recreate the item and put it back in the cache. This mode ensures that there is always * * data in the cache.
Page output of ASP.NET cache application
Page output is cached in memory to store the contents of the processed ASP.NET page. This mechanism allows ASP.NET to send a page response to the client without having to go through the page processing life cycle again. The page output cache is especially useful for pages that change infrequently but require a lot of processing to create. For example, if you create a high-traffic web page to display data that does not need to be updated frequently, the page output cache can greatly improve the performance of the page. You can configure page caching separately for each page, or you can create a cache profile in the Web.config file. With a cache profile, you can use cache settings in multiple pages by defining them only once.
Page output caching provides two page caching models: full page cache and partial page cache. Full-page caching allows the entire contents of the page to be kept in memory and used to complete client requests. Partial page caching allows part of the page to be cached, while others are dynamic.
Partial page caching can work in two ways: control caching and post-cache replacement. Control caching, sometimes referred to as segmented caching, allows you to include information in a user control and then mark the user control as cacheable to cache part of the page output. This method caches specific content in the page, not the entire page, so you need to recreate the entire page each time. For example, if you want to create a page that displays a large amount of dynamic content, such as stock information, some of which are static (such as weekly summaries), you can place the static parts in the user control and allow the content to be cached.
Post-cache substitution is the opposite of control caching. The entire page is cached in this way, but the segments in the page are dynamic. For example, if you want to create a page that is static within a specified period of time, you can set the entire page to be cached. If you add a Label control to a page that displays a user name, the contents of the Label will remain the same for each page refresh and for each user, always displaying the name of the user who requested the page before caching it. However, using the post-cache replacement mechanism, you can configure the page to be cached, but mark individual parts of the page as non-cacheable. In this case, you can add Label controls to the non-cacheable parts, which will create them dynamically for each user and each page request.
Cache the page according to the request parameters
In addition to caching a single version of a page, the ASP.NET page output cache provides features to create multiple versions of a page that vary according to the request parameters.
Automatically remove data
ASP.NET can remove data from the cache for one of the following reasons:
Due to insufficient memory on the server, start a process called "cleanup".
Because the item in the cache has expired.
Because the dependency of the item has changed.
To help manage cache items, ASP.NET notifies the application when the item is removed from the cache.
Clear
Cleanup is the process of removing items from the cache when there is insufficient memory. Items are removed if they are not accessed for a period of time or are marked as low priority when they are added to the cache. ASP.NET uses the CacheItemPriority object to determine which items to clean up first.
Overdue
In addition to cleanup, ASP.NET automatically removes cached items from the cache when they expire. When you add an item to the cache, you can set its expiration time as described in the following table.
ASP.NET cache expiration type
Adjustable expiration
Specifies how long an item has expired since it was last accessed. For example, you can set an item to expire 20 minutes after it was last accessed in the cache.
Absolute expiration
Specifies that an item expires at a set time, regardless of the frequency of access. For example, you can set an item to expire at 6:00 PM, or four hours later.
Dependency item
You can configure the lifetime of an item in the cache to depend on other application elements, such as a file or database. When the element on which the cache item depends changes, ASP.NET removes the item from the cache. For example, if your website displays a report that was created by the application through a XML file, you can place the report in the cache and configure it to depend on the XML file. When the XML file changes, ASP.NET removes the report from the cache. When the code requests the report, the code first determines whether the report is in the cache, and if not, the code recreates the report. As a result, a * version of the report is always available.
For ASP.NET caching applications, it supports the following described dependencies:
Key dependency
Items in the application cache are stored in key / value pairs. Key dependencies allow items to depend on the key of another item in the application cache. If the original item is removed, items with key dependencies are also removed. For example, you can add a cache item named ReportsValid, and then cache several reports that depend on the ReportsValid key. When the ReportsValid entry is removed, all cache reports that depend on it are also removed from the cache.
File dependency
Items in the cache depend on external files. If the file is modified or deleted, the cached item is also removed.
SQL dependency
Items in the cache depend on changes to tables in Microsoft SQL Server 2005, SQL Server 2000, or SQL Server 2000 databases. For SQL Server 2005, items in the cache can depend on a row in the table.
Aggregate dependency
By using items in the AggregateCacheDependency class cache, it depends on multiple elements. If any dependencies change, the item is removed from the cache.
Custom dependency
You can configure items in the cache with dependencies created by your own code. For example, you can create a custom Web service cache dependency that removes data from the cache when a specific value is obtained by calling the Web service.
ASP.NET cache application item removal notification
You can be notified when an item is removed from the application cache. For example, if you have an item that takes a lot of processing time to create, when you remove the item from the cache, you will be notified so that it can be replaced immediately. In this way, the user does not have to wait for the item to be processed the next time it is requested.
After reading the above, do you have any further understanding of the concept and application process of ASP.NET caching? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.