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
rs.MoveNext
Loop
'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!

Ian Stallings is a 26 year old Software Engineer from the Washington DC
area. He has experience in Internet/Intranet development using ASP, VB,
Java, SQL Server, and IIS. Prior to devoting his career to application
development he worked as a systems administrator at a small ISP.

When not developing applications or tinkering with computers, he masquerades
as a normal human being

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.