By Julian Sitkewich
Note from the WebMaster (Scott Mitchell):
Hey-yo. I just wanted to share my opinions on this article. It is a neat idea, cachine a web page. At first, you might be inclined to think it would be quicker than using a standard HTML page, especially for an HTML page that is requested often. I don't know for sure, but I would assume the HTML page approach would be faster. To use the
Application object, you need to be using an ASP page.
This requires that the page be processed before the HTML output is sent to the user. While you may argue
that this is quicker than having to read the HTML file off the disk each time it is requested, rest
assured that IIS caches commonly requested pages, so there is not that disk access each time.
However! That does not mean that this is not a great article. It discusses some important
Application object, and the
FileSystemObject. Also, Julian makes an intersting comment near the end of this article, about
how this concept can be expanded. This article is definately worth a read! OK, enough from me, read on!
Have you ever wanted to "cache" a page or file in server memory for quick performance? Well this quick
tutorial can show you how using the
Application Object. (Unfamiliar with the
Application Object? Here is an article that might help!
Caching Data, by Ian Stallings)
When your web application is started, the
Application section of the
is executed. For example:
What we will do, is place some code inside the
Application_OnStart sub to load a web page
Application object. All items loaded into any
Application Object are
globally available to users and exist until the Application exits (server rebooted, etc.). The code
essentially reads a web page using the
FileSystemObject and loads it directly into
Application Object. This makes the page globally available when the Application is
Ok, let's look at this simple code:
Alright then, let's put it into action.
Place the web page
cached.html in your root
directory, which just contains simple HTML. And then place the ASP page
DisplayCached.asp in your root
directory as well. This page just contains a one-liner
Response.Write to display the
contents of our
Application Object. Now copy the above code and add it to your
Global.asa file. You might want to retain the code that is already inside
Application_OnStart, so be careful how you paste.
Restart your web application (restarting your computer is one way you can do this) and then load the
DisplayCached.asp. You should see the contents of
Pretty cool, huh!? Now that we've accomplished this, what other kinds of content could you set an
Application object to? A commonly used recordset, perhaps? Or maybe some non-HTML thing.
This could be done by setting
Response.ContentType = "type/subtype" in
Hmmm... What about modifying the contents? Keep in mind we are using server memory when storing an
Have fun with it, try something new, and learn... :)
Global.asa, but were afraid to ask!
DisplayCached.aspin text format
cached.htmlin text format.