Deep analysis of ASP.net 2.0 buffering mechanism

Source: Internet
Author: User
Tags new features advantage

Buffering is one of the key concerns developers build ASP.net 2.0 Web applications. This article attempts to comprehensively analyze the new buffering mechanism provided by ASP.net 2.0 through three sample pages.

First, Introduction

The ASP.net 1.x Cache API is a revolutionary feature. When the contents of an XML file or another buffer item change, the Cache API provides such capabilities as declarative output buffering, programmatic control of output buffering, and invalidation of buffers. Although this greatly improves the performance of Web applications, unfortunately, ASP.net 1.x does not provide a mechanism to invalidate data in a cached object when the data in the database changes. In the end, this feature was added to ASP.net 2.0. In addition, ASP.net 2.0 provides a specific feature to buffer the output of a SqlDataSource control-you can take advantage of the buffering advantage without writing a single line of code. In this article, let's discuss these new buffering features and how to apply them to your Web application.

In asp.net 2.0, buffering is improved in a variety of ways. Perhaps the most noticeable improvement is the introduction of a database-triggered cache invalidation mechanism. In ASP.net 1.x, you can invalidate a buffer based on predefined criteria such as changes in an XML file, changes in another cache entry, and so on. With this feature, you can delete or invalidate the entry from the cache when the data or another buffer item changes. However, when data in a SQL Server database changes, the ASP.net 1.x cache API does not allow you to invalidate an item in the cache, although most applications require this capability. In contrast, ASP.net 2.0 pays special attention to this-by providing a database-triggered cache invalidation, it enables you to ensure that items in the cache are kept synchronized with changes in the database.

ASP.net 2.0 Another important buffering feature is the ability to support buffering at the SqlDataSource level. The SqlDataSource control enables you to manipulate multiple databases, such as SQL Server, OLE DB, ODBC, and Oracle databases, and enables you to select, Update, delete, and insert data using SQL commands. Now, with the ability to set buffering properties at the SqlDataSource Control level, you can control the buffered data more carefully.

ASP.net 2.0 also provides a new substitution control that you can use to inject dynamic content into another buffered Web page. If you have a page that starts output buffering but still wants to display dynamic content (which needs to be regenerated each time you request the page), you may consider using the substitution control.

In the following sections, I will analyze the above features in detail and provide relevant examples.

Tips This article provides three simple but complete aspx page source code, I experimented with Visual Studio 2005 in a simple Web engineering caching and previewed the three pages in a browser. As for how to build a connection with the SQL Server 2005/2000/7.0 sample database Northwind, skip here.

Ii. implementing a time-based cache invalidation in the SqlDataSource control

Asp. NET buffering is an important feature that can improve the performance of Web applications. In fact, the most obvious way to improve the performance of a database-driven Web application is to be cleverly grasped by the buffer mechanism. In most cases, retrieving data from a database becomes one of the slowest web operations you can achieve. However, if you can properly cache database data in memory and avoid accessing the database whenever possible at every page request, you will be able to significantly improve the performance of your application.

ASP.net 2.0 provides a stronger buffering feature than the ASP.net 1.x. One of the new features is that it can designate the caching property as part of the data source control declaration. The new data source control in ASP.net 2.0 enables you to "seamlessly" take advantage of the ASP.net 2.0 new buffering feature, allowing you to set the caching property as part of the SqlDataSource Control declaration.

Typically, you can support buffering by setting the following two properties in the SqlDataSource Control:

enablecaching-by setting this property to True, you can start a SqlDataSource control's buffering function.

Cacheduration-This property allows you to set or get the duration of the buffered data in the SqlDataSource control (this property is specified in seconds).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.