Caching is not always this straightforward. For example, here are the
other things that might affect whether a cached copy was okay to send
out, or which one would be sent. These are not necessarily part of the
URL (the cache tag):
- Accept-Encoding on the browser request (can I send compressed or not?)
- User-Agent (Mac's had horrible font defaults we had to override
because of user complaints; I know, it sucks; so do customer complaints)
- Cookie values - user comes to our home page and it says "Welcome
back whatever-your-name-is"
Another complication is that using cache tags based on the URL means
that all URL references have to be canonical (alphabetize parameters,
don't include any empty parameters like &type=&xyz=blah, etc) or the
cache doesn't work.
A generalized cache mechanism would be useful, but it's also
very easy to do trivial ad-hoc ones, like:
ns_share dircache
... generate a cache tag ...
if {[info exists dircache($tag)]} {
ns_return 200 text/html $dircache($tag)
return
}
... generate content ..
set dircache($tag) $content
ns_return 200 text/html $content
These can be a huge performance win for complex dynamic pages, and
doing a few of these will often relieve 80% of a server's performance
problems.
I'd suggest a two-level architecture, with the underlying mechanism
being very flexible as to flushing/re-fill policy and cache tags,
and then an easy-to-enable URL-based cache built on top. That way,
really dynamic content sites can use the lower-level mechanism while
sites that just "want it to go faster" can turn on the URL cache
with a few config directives.
Another useful feature would be placeholders. Many times dynamic
content can be generated with placeholders and cached, then
placeholders are modified before sending out the cached copy.
We do this for click tracking for example.
Jim
> Dossy wrote:
>
> > - client requests a URL
> > - server looks to see if the page is cacheable
> > - if page is cacheable, and is cached, serve page out of cache
> > - if page is cacheable, and is not cached, generate the cached
> > page, then serve the page out of cache
> > - if the page is not cacheable, generate it dynamically and serve
> > the generated page
> > - if the page is static, treat the static page as though it was
> > actually the cached version of a dynamic page, and serve it out
> > of "cache"
>
> Someone here had a tcl module called "cache tools" that did a very
> similar thing. And it isn't complicated to do this at all. Also, the aD
> template system seems to cache (in memory) the parsed adp templates.
> Writing them to disk might not be that difficult.
>
> --Tom Jackson
>