Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Enterprise, Web
Expertise: Beginner
Mar 10, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Cache Commonly Used Select Lists in Application Object

You should always prefer to cache commonly used select lists in the Application object. In a typical Web application, you make a database server trip to get to the list. The list could be a list of states, a list of frequencies (monthly, annually, weekly, etc.), or a list of credit card types. Because the data in these kinds of lists are static, you can optimize the round trip to the database server by caching them in the Application object. Every time you need to display one such static list in your ASP page, first check in the Application object. If it is not there, then get it from the database and make sure that you cache it so that subsequent usage will retrieve it from the Application object instead of the database.

This implementation will save you at least one hit per list per page. You can decide on the format of the list. Because drop-down lists require <SELECT> and <OPTION> tags, I always cache the entire string (with option tag) in the app object. A typical string would look like <OPTION>Alabama <OPTION>Arkansas <OPTION>Arizona <OPTION>California, and so forth. For example, if you need to display a list of states in many Web pages then:

Dim strListofStates

strListofStates = Application("LIST_OF_STATES") 
If (strListofStates = "") Then 
    ' Get the list from database
    ' Cache it in application object for subsequent usages
    Application ("LIST_OF_STATES") = strListofStates
End If
Response.Write strListofStates
Deepak Pant
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date