Using Aspnet Components

Extra

If you want to cache the page per user session, you can cache based on the users cookie. Authentication cookies are used to map a user to a session. Open two instances of Internet Explorer and note the generated times for each instance and note they are not sharing the same cached page. See ASPPageCache_ex1.aspx on the CD for a page that demonstrates this directive.

Example:

<%@ OutputCache Duration="60" VaryByHeader="Cookie" %>

You can bypass a cached page each time the user submits different Form or QueryString data to a page. See ASPPageCache_ex2.aspx on the CD for a page that demonstrates this directive.

Example:

<%@ OutputCache Duration="60" VaryByParam="*" %>

^ hltp://Iocalhost/ASPPageCache.aspx - Microsoft Internet Explore

File Edit View Favorites Tools Help jsjx]

Address |g] http:/7localhoît>ASPPageCache.aip*

Welcome to mylifetimegoals.com

Here are the are some books that will help you reach your career goals.

The Busy Executive's Database Guide

An overview of available database systems with emphasis on common business applications, Illustrated,

19,99

Cooking with Computers: Surreptitious Balance Sheets

Helpful hints on how to use your electronic resources to the best advantage,

11,95

You Can Combat Computer Stress!

The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations.

2,99

Straight Talk About Computers

Annotated analysis of what computers can do for you: a no-hype guide for the critical user.

19,99

Generated on: 8/1/2001 9:31:40 AM

Local intranet

Generated on: 8/1/2001 9:31:40 AM

-■ You can observe that the generated time is 9:31:40 AM.

0 Press F5 to refresh the page.

Local intranet http:/Ylocalhost/ASPPageCache.aspx - Microsoft Internet Explorer

File Edit View Favorites Tools Help

Address |g] http:/7localhoît>ASPPageCache.aip*

Welcome to mylifetimegoals.com

Here are the are some books that will help you reach your career goals.

The Busy Executive's Database Guide

An overview of available database systems with emphasis on common business applications, Illustrated,

19,99

Cooking with Computers: Surreptitious Balance Sheets

Helpful hints on how to use your electronic resources to the best advantage,

11,95

You Can Combat Computer Stress!

The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations.

2,99

Straight Talk About Computers

Annotated analysis of what computers can do for you: a no-hype guide for the critical user.

19,99

g] Dene

g] Dene

■ You can observe the generated time is the same as before (9:31:40 AM), indicating you are viewing a cached page.

Q Wait for more than 60 seconds and refresh the Web page.

■ The generated time updates, indicating that the cached page was not used.

USE THE ASP.NET DATA CACHE

You can increase performance on your ASP.NET Web pages by placing data for your Web pages in a cache on the Web server. When using a data cache, you can cache a dataset on the Web server so that you do not have to go back to the database when the page is refreshed.

To place data into the cache, you can use Cache["name"] = value, where name is the name you want to access the information by in code and value is the value for the name. To read the data out of the cache, you can use variable = Cache["name"]. Note that for storing data into cache, you cast the data in the cache to a DataView data type. With the cache, you can set memory and duration by respectively setting the length of the cache and setting a sliding expiration for the cache.

When caching data on your Web pages, you need to check to see if the cache exists before using it. If it does not exist —for instance, it expires— then you execute the code necessary to retrieve the data from the database again. One way of checking to see if the cache exists is by checking to see if the cache is null.

USE THE ASP.NET DATA CACHE

USE THE ASP.NET DATA CACHE

Q Open the

DatagridTemplate.aspx template from the Code Templates directory.

< Try to read the DataView out of the page cache.

Create the new DataView.

° Add an else message to indicate that the data cache was used.

Q Open the

DatagridTemplate.aspx template from the Code Templates directory.

Create a new DataView variable.

< Try to read the DataView out of the page cache.

-Q If there was nothing in the cache to retrieve, get a new DataView.

Create the new DataView.

"0 Cache the DataView.

_Q Update the label on the page to show that the DataSet was created explicitly.

° Add an else message to indicate that the data cache was used.

Update the DataSource to be dataviewTitles.

Was this article helpful?

0 0

Post a comment