When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Thursday, May 20, 1999

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.

- continued -

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


ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article