PEAR::Cache can cache more than just output. It also can cache the results of a function call:
<?php
require_once('Cache/Function.php');
$fcache = new Cache_Function();
/* Caching the result of a standard PHP function */
$result = $fcache->call('myfunction');
$result = $fcache->call('anotherfunction', 'parameter');
/* Caching the result of a static method in a class */
$result = $fcache->call('myclass::mymethod', 'parameter');
/* Caching the results of method being called against a specific instance. In
this case, calling the method $mymethod of the $bar object */
$result = $fcache->call('bar->mymethod');
?>