Output Cache API Change
[email protected] (Ulf Wendel) Wed, 28 Feb 2001 15:03:09 +0100
| Newsgroups | php.pear |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Christian should not have given me a CVS account for the Output Cache, I
changed the API ;-). Here're the thought behind the new API. The old
gave you a script that looks like:
$cache = new cache(...);
if ($cache->Start()) {
// do the long time computation if neccessary
}
// output the stuff
$cache->End()
I applied some changes to that you now can do this to cache a whole
script. This is a very handy way if you place the cache control stuff in
the auto_prepend and auto_append file:
$cache = new cache(...)
if ($content = $cache->Start()) {
print $content;
// WARNING: script executions stops!
die();
}
// do the long time computation
print $cache->End();
You can still get the old behaviour (to cache parts of a script) by:
$cache = new cache(...)
if (!($content = $cache->Start()) {
// do the long time computation
print $cache->End()
} else
print $content;
}
I think this a good change that gives many users that do not have access
to a php interpreter with one of the caches (Bware, APC, Zend) a quick
and easy way to cache entire scripts. See the code
http://cvs.nomad.ch/index.cgi/pear/Cache/Output.php for more detailed
informations.
Ulf