I am attempting to use Zend_Cache_Frontend_Function to cache some of my own function calls.
The cache is set up like so:
$manager = new Zend_Cache_Manager();
$frontendOptions = array(
'lifetime' => intval(CACHELIFETIME),
'automatic_serialization' => true);
$backendOptions = array('cache_dir' => CACHEDIR);
$funcCache = Zend_Cache::factory('Function',
'File',
$frontendOptions,
$backendOptions);
$manager->setCache('function', $funcCache);
I then use the cache like so:
$country_name = "UK";
$country_id = 1;
$country = new Default_Db_Table_Country();
$country = $cache->call(array($country, "getCountryByName"), array($country_name, $id));
Even after calling this several times, the function getCountryByName() is still being called and the database query within it run.
Am I using this correctly? How can I stop the call to getCountryByName() happening multiple times?
Thanks
Edit:
Looking at the source, it seems that call() uses output buffering, if this is the case then my functions output nothing, they only return objects. Thus making Zend_Cache_Frontend_Function useless in this case?
It would seem that
Zend_Cache_Frontend_Classis the way to go and notFunction. I need to set the class before each call to ensure the right object is being used;This Frontend does cache objects, arrays, etc.