zend Cache 使用方法实例


<?php
require’Zend/Loader.php’;
Zend_Loader::loadClass(’Zend_Cache’);
Zend_Loader::loadClass(’Zend_Config’);
Zend_Loader::loadClass(’Zend_Registry’);
$config=newZend_Config_Ini(’configsecr/config.ini’);
define(’CACHE_DIR’,FDROOT.’/’.’tmp/’);
 
 
 
$frontendOptions=$config->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);
 
 
$viewRenderer=$_cache->load(’viewRenderer’);//试图从缓存加载变量
if(!$viewRendererinstanceofSomething)//加载不成功
{
$viewRenderer=newSomething();
 
$_cache->save($viewRenderer,’viewRenderer’);//保存变量到换存
}
 
?>

你可能感兴趣的:(PHP,cache,Zend)