Zend_Cache for Web Services
My current project involves a number of SOAP Web Services requests to retrieve information from our Fedora repository. To help minimize overhead from HTTP requests, I’m using Zend Framework’s Zend_Cache_Frontend_Class to wrap the whole Fedora/PHP interface class. Zend_Cache allows me to implement this style of caching with only a single line of code.
Our web services consumer provides a couple of access methods that can be safely cached:
class Fedora_Object { /* .... */ public function getDissemination($pid, $sDefPid, $methodName, $parameters, $asOfDateTime = null) { try { return Fedora_Repository::get('API-A', $pid)->getDissemination(array('pid' => $pid, 'serviceDefinitionPid' => $sDefPid, 'methodName' => $methodName, 'parameters' => $parameters, 'asOfDateTime' => $asOfDateTime)); } catch(SoapFault $s) { return $s; } } /* .... */ }
In the bootstrap file, instead of initializing the Fedora_Object class, I wrap it in a Zend_Cache instance:
$fedora = Zend_Cache::factory('Class', 'File', array('cached_entity' => new Fedora_Object(), 'cached_methods' => array('getObjectXML', 'getDatastreamDissemination', 'getDissemination'), 'cache_by_default' => false));
This code tells Zend_Cache to cache only the specified cached_methods and pass everything else through. Easy.