I am running a classic vbscript ASP site with a SQL2008 database. There are a few pages that are processor-heavy, but don’t actually change that often. Ideally, I would like the server to process these once a night, perhaps into HTML pages, that can then fly off the server, rather than having to be processed for each user.
Any ideas how I can make this happen?
The application itself works very well, so I am not keen to rewrite the whole thing in another scripting language, even if classic asp is a bit over the hill!!
Yes :
You didn’t specify which parts of the pages are “processor heavy” but I will assume it’s the query and processing of the SQL data. One idea is to retrieve the data and store it as a cached file, in the filesystem. XML is a good choice for the data format.
Whereas your original code is something like this:
…your modified code can look like this:
This is a general caching approach and can be applied to a situation where you’ve got
query parameters determining the output. Simply generate the name of the cache file based on all the constituent parameters. So if the results depend on query parameters named p1 and p2, then when
p1andp2have the values1234andbluerespectively, the cache file might be namedcache-1234-blue.xml. If you have 5 distinct queries, you can cache them asquery1-1234-blue.xml,query2-1234-blue.xmland so on.You need not do this “nightly”. You can include in your code a cache lifetime, and in place of the “if cache file exists” test, use “if cache file exists and is fresh”. To do that just get the last modified timestamp on the cache file, and see if it is older than your cache lifetime.
This could be 10 minutes, 10 hours, 10 requests, whatever you like.
I said above that XML is a good choice for the data format in the cachefile. ADO has a SaveAsXML method, and you can also generate XML directly from SQL2008 using the
FOR XMLclause appended to the query.If the “processor heavy” part is not the query and retrieval, but is the generation of the html page, then you could apply the same sort of approach, but simply cache the html file directly.