0% found this document useful (0 votes)
57 views3 pages

Class Notes 1

The document discusses caching techniques in ASP to improve performance by reducing data retrieval time. It explains output caching for storing prepared data and input caching for saving data without its presentation. Examples in JScript and VBScript illustrate how to implement these caching methods effectively within an application.

Uploaded by

madaboutrc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views3 pages

Class Notes 1

The document discusses caching techniques in ASP to improve performance by reducing data retrieval time. It explains output caching for storing prepared data and input caching for saving data without its presentation. Examples in JScript and VBScript illustrate how to implement these caching methods effectively within an application.

Uploaded by

madaboutrc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Caching ASP Content

 06/16/2017
 2 minutes to read

When clients access your ASP page, the response can come from one of the following
two sources.

 The ASP page can either obtain information from server resources, such as from
data that has been persisted to a database, or

 The ASP page can obtain information from within the application.

Retrieving data from a resource outside the application requires more processing steps,
and therefore requires more time than generating the data from within the application
space.

If the requested resource has already been prepared during a previous request, the
application can retrieve that data faster if it is stored in a cache. This form of caching is
called output caching. Output caching is particularly suitable when returning the same
data in the same format for many different requests. For example, one common task for
developing an input form is to gather persisted data as members of a drop-down list
box. This is preferable to writing the entries directly into the HTML page, because
updates to the persisted data will automatically be reflected in the form.

The following example shows you how to use JScript to perform output caching. In this
example, the getSportsListBox function creates a list box from persisted data. The list
box is added to the application space so that clients can access it more quickly than they
could if they populated the list box on an individual basis. The example assumes that a
Data Source Name (DSN) called "Sports" is defined on the server.

jscriptCopy

<%@ LANGUAGE=JavaScript %>


<HTML>
<BODY>
<FORM METHOD=post>

What is your favorite sport? <%= getSportsListBox() %>


<P>

<INPUT TYPE=submit>
</FORM>
</BODY>
</HTML>

<%
function getSportsListBox()
{
SportsListBox = Application("SportsListBox");
If (SportsListBox != null) return SportsListBox;
crlf = [Link](13, 10);
SportsListBox = "<select name=Sports>" + crlf;
SQL = "SELECT SportName FROM Sports ORDER BY SportName";
cnnSports = [Link]("[Link]");
[Link]("Sports", "WebUser", "WebPassword");
rstSports = [Link](SQL);
fldSportName = rstSports("SportName");
While (![Link])
{
SportsListBox = SportsListBox + " <option>" + fldSportName + "</option>" + crlf;
[Link]();
}
SportsListBox = SportsListBox + "</select>"
Application("SportsListBox") = SportsListBox;
return(SportsListBox);
}
%>

In some circumstances, an application receives many different requests for the same
data, but the presentation of that data needs to change for each request. In this case,
use input caching. With input caching the data is saved, but not the presentation of it.
A Dictionary object or ADO recordsets can be used for input caching.

Excerpt from [Link]:

The following examples show you how to use the VBScript scripting language to cache
data by adding a connectionless recordset to your application. ASP scripts within the
application space can then access the recordset rather than retrieve the data from the
database.

The first example exists in the [Link] file for the application. It creates the recordset
and adds it to the application space. The second example is an ASP script in the
application that populates the recordset and makes it connectionless by setting
the ActiveConnection property to Nothing. The ASP script then clones this recordset
and iterates through its values, which is much faster than accessing the database itself.
This technique is appropriate only if you know that the data that will be used to
populate the recordset is relatively stable.

VBScriptCopy

<OBJECT ID=rsCustomers PROGID="[Link]" RUNAT="Server" SCOPE="Application">


</OBJECT>
<!--METADATA TYPE="TypeLib" FILE = "C:\Program Files\Common
Files\system\ado\[Link]"-->

<%
SQL = "SELECT CompanyName, City FROM Customers"
Cnn = "DSN=AdvWorks" [Link] = adUseClient
[Link] SQL, Cnn, adOpenStatic, AdLockReadOnly
[Link] = Nothing
Set myCustomers = Application("rsCustomers").Clone
Set CompanyName = myCustomers("CompanyName")
Set City = myCustomers("City")
Do Until [Link]
%>
<B><%= CompanyName %></B> is located in <B><%= City %></B>.<P>
<%
[Link]
Loop
%>

You might also like