The example in this article describes the usage of Zend Framework cache Cache. Share it with everyone for your reference, the details are as follows:
cache->cache->frontend->toArray(); $backendOptions = $config->cache->cache->backend->toArray(); $frontendName = $frontendOptions['name']; unset($frontendOptions['name']); $backendName = $backendOptions['name']; unset($backendOptions['name']); if (empty($backendOptions['cache_dir'])) { $backendOptions['cache_dir'] = CACHE_DIR; } $_cache = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions); Zend_Registry::set('cache', $_cache); /*使用cache*/ $viewRenderer = $_cache->load('viewRenderer'); //试图从缓存加载变量 if (!$viewRenderer instanceof Something)//加载不成功 { $viewRenderer = new Something(); /*some other work*/ $_cache->save($viewRenderer, 'viewRenderer');//保存变量到换存 } /*这只是一种应用,还可以轻松缓存整页;也可将缓存存到数据库或者内存。*/ ?>
I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.
For more articles related to simple examples of Zend Framework cache Cache usage, please pay attention to the PHP Chinese website!