Zend_Cache
第 2 版(2008-06-29 02:29:25 · akkun_choi)を表示しています。 最新版に戻る
Frontend(キャッシュ対象)は指定のクラスやファイルやページや出力などが指定できる。
Backend(キャッシュ保管場所)はファイルやmemcachedやDBなどが使える。
Zend_Configをキャッシュするサンプル
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Cache.php';
$file = 'config.ini';
$frontendOptions = array(
'lifetime' => 7200, // キャッシュの有効期限を 2 時間とします
'automatic_serialization' => true,
'master_file' => $file
);
$backendOptions = array(
'cache_dir' => './tmp/' // キャッシュファイルを書き込むディレクトリ
);
// Zend_Cache_Core オブジェクトを取得します
$cache = Zend_Cache::factory('File', 'File', $frontendOptions, $backendOptions);
if (!$config = $cache->load('config')){
//$options['nestSeparator'] = ':';
$config = new Zend_Config_Ini($file, null, array('allowModifications' => true));
$cache->save($config, 'config');
}else{
echo "use cache\n";
}
var_dump($config->toArray());