Page 280 - DCAP312_WEB_TECHNOLOGIES_II
P. 280
Web Technologies-II
Notes The above code retrieves the connection string value defined in the connectionString attribute
of the Northwind connection string element.
The SqlDataSource control also has the EnableCaching property set to true, which results
in the SqlDataSource automatically caching the data retrieved by the SelectCommand. The
CacheDuration property enables us to specify (in seconds) how long the data should be cached
before it is refreshed from the database. By default, the SqlDataSource will cache data using an
absolute expiration policy, meaning that the data will be refreshed every so many seconds as
specified in the CacheDuration property.
We also have the option of configuring the SqlDataSource to use a sliding expiration policy,
by which the data is not dropped as long as it continues to be accessed. Employing a sliding
expiration policy is useful whenever we have a large number of items that need to be cached,
because the policy enables us to keep only the most frequently accessed items in memory.
In the above example, we cached the results of the SQL query for 10 seconds by setting the
EnableCaching and CacheDuration attributes to True and 10, respectively (see the output
Figure 14.7).
Figure 14.7: CacheDuration Attributes
As we can see, the values in the timestamp column remain the same for 10 seconds. After that
they will be refreshed with the new timestamp values from the database.
One of the most important factors in building high-performance, scalable Web applications is the
ability to store items, whether data objects, pages, or parts of a page, in memory the initial time
they are requested. We can store these items on the Web server or other software in the request
stream, such as the proxy server or browser. This allows us to avoid recreating information that
satisfied a previous request, particularly information that demands significant processor time
or other resources. Known as caching, it allows us to use a number of techniques to store page
output or application data across HTTP requests and reuse it. Thus, the server does not have
to recreate information, saving time and resources.
ASP.NET provides two types of caching that we can use to create high-performance Web
applications. The first is called output caching, which allows us to store dynamic page and
user control responses on any HTTP 1.1 cache-capable device in the output stream, from the
originating server to the requesting browser. On subsequent requests, the page or user control
code is not executed; the cached output is used to satisfy the request. The second type of caching
274 LOVELY PROFESSIONAL UNIVERSITY