To read the article online, visit

Caching Data
By Ian Stallings

What is cache? Cache is data that is stored in memory as opposed to data stored on the hard drive, making it faster.

Storing data in cache makes accessing it allot easier than creating it every time someone accesses your site. For instance, say on your site there is a drop-down list that doesn't change to often and the information is pulled from a database. Instead of calling the database each and every time someone visits the site, we can cache it in memory to increase performance.

Application Object
The Application object stores data that is application wide. In other words, it stores data for that site only. Each site is considered an "application". Application can be stored in the global.asa file or you can place information in it using ASP.

Ok, now on to the code. In this example I have a drop-down menu that the Application object as a variable. So instead of connecting to the database each time it needs to write the menu, it will pull it from this variable.

Here is the code:
(I will explain it in the comments)

<%= Application("ListBox")%>

'here we define the variable'
as an a application object
ListBox = Application("ListBox")

'we then check to see if it is already set
If ListBox = "" Then
   'it's not, so we go to the database and retrieve it
   Set oConn = Server.CreateObject("ADODB.Connection")
   oConn.Open "DSN=travel;UID=;PWD="

   sql = "SELECT * FROM types"

   Set rs = oConn.Execute(sql)

   crlf = chr(13) & chr(10)

   'Now we assign the recordset to the 'ListBox'
   'variable using a loop
   ListBox = "<select name='listbox'>" & crlf
   Do Until rs.EOF
      Listbox = ListBox & " <option>" & _
                rs("type") & "</option>" & crlf

   'we then assign the variable to the 
   'Application object below
   Application("ListBox") = ListBox
End If

Since the data is only pulled once and then stored in memory it will be quicker. This is not neccesary with every site, but if you have a hardcore app and you want maximum performance than you might want to use it.

Happy Programming!

Article Information
Article Title: Caching Data
Article Author: Ian Stallings
Published Date: Thursday, May 20, 1999
Article URL:

Copyright 2019 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers