ZF-9737: Zend_Applicaton_Resource_Cachemanager cannot create a Zend Server backend

Description

When using the cache manager via a Zend_Application resource, the Zend Server backends are not able to be loaded.

application.ini resources.cachemanager.youtube.frontend.name = Core resources.cachemanager.youtube.frontend.options.automatic_serialization = true resources.cachemanager.youtube.backend.name = ZendServer_Disk

This causes the backend to be named ZendserverDisk, which does not exist. Changing the application.ini file to

resources.cachemanager.youtube.backend.name = Zend_Cache_Backend_ZendServer_Disk

does not work either because the $customBackendNaming value is not available when calling Zend_Cache_Manager::getCache()

Comments

I have created a fix for this issue. It does not solve the naming problem, but it does allow for the custom naming and autoloading arguments to be passed to the Zend_Cache::factory call. That way you can at least explicitly create that backend.

Index: tests/Zend/Application/Resource/CacheManagerTest.php

--- tests/Zend/Application/Resource/CacheManagerTest.php (revision 21970) +++ tests/Zend/Application/Resource/CacheManagerTest.php (working copy) @@ -182,6 +182,31 @@ $cache = $manager->getCache('foo'); $this->assertTrue($cache instanceof Zend_Cache_Core); } +
+ public function testNamespacedBackend() + { + $options = array( + 'foo' => array( + 'frontend' => array( + 'name' => 'Zend_Cache_Core', + 'options' => array( + 'lifetime' => 7200, + 'customFrontendNaming' => true + ), + ), + 'backend' => array( + 'name' => 'Zend_Cache_Backend_ZendServer_Disk', + 'options' => array( + 'customBackendNaming' => true + ) + ), + ), + ); + $resource = new Zend_Application_Resource_Cachemanager($options); + $manager = $resource->init(); + $cache = $manager->getCache('foo')->getBackend(); + $this->assertTrue($cache instanceof Zend_Cache_Backend_ZendServer_Disk);
+ } }

if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_CacheManagerTest::main') {

Index: library/Zend/Cache/Manager.php

--- library/Zend/Cache/Manager.php (revision 21970) +++ library/Zend/Cache/Manager.php (working copy) @@ -171,7 +171,10 @@ $this->_optionTemplates[$name]['frontend']['name'], $this->_optionTemplates[$name]['backend']['name'], isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(), - isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array() + isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array(), + isset($this->_optionTemplates[$name]['frontend']['options']['customFrontendNaming']) ? $this->_optionTemplates[$name]['frontend']['options']['customFrontendNaming'] : false, + isset($this->_optionTemplates[$name]['backend']['options']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['options']['customBackendNaming'] : false, + isset($this->_optionTemplates[$name]['backend']['options']['autoload']) ? $this->_optionTemplates[$name]['backend']['options']['autoload'] : false ); return $this->_caches[$name]; }

Index: library/Zend/Cache.php

--- library/Zend/Cache.php (revision 21970) +++ library/Zend/Cache.php (working copy) @@ -143,6 +143,7 @@ } if (!$autoload) { $file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php'; +
if (!(self::_isReadable($file))) { self::throwException("file $file not found in include_path"); }

unit test is already included added within [ZF-9738] fix, updated patch is attached.

Patch looks good, but it's necessary to check if it's the best way to set additional parameters through backend/frontend option arrays

Done.

Provided patch is changed a bit.

Thanks for fixing. Reopening however due to missing unit tests.

@Alexander In your commit Zend_Cache_Manager, corrected ZF-9134 and ZF-9240.

Thanks ;)

Test added in trunk r22617, applied to release 1.10 r22618.