我正在尝试使用php中的zend缓存来实现缓存查询结果
我使用以下代码
<?php
include 'zend/library/Zend/cache.php';
$frontendOptions = array(
‘lifetime’ => 10,
‘automatic_serialization’ => true
);
$backendOptions = array(
'cache_dir' => 'tmp/'
);
$cache = Zend_Server_Cache::factory(‘Core’, ‘File’, $frontendOptions, $backendOptions);
$id = ‘rs’;
$start_time = microtime(true);
if(!($data = $cache->load($id)))
{
echo "Not found in Cache<br />";
mysql_connect('localhost', 'user', 'pass');
mysql_select_db('dbname');
$query ='select * from tablename';
$rs = mysql_query($query);
$data = array();
while($row = mysql_fetch_assoc($rs))
{
$data[] = $row;
}
$cache->save($data);
}
else
{
echo "Running from Cache<br />";
}
//echo ‘<pre>’;
//print_r($data);
//echo ‘</pre>’;
//echo sprintf(microtime(true) – $start_time);
?>
我在13行收到一个错误,表示调用了未定义的zend_server_cache :: factory()方法。
zend_server_cache文件存在于我的zend服务器文件夹中。但工厂方法不可用。这就是为什么我在该行收到错误。请指导是否有任何方法在类中实现工厂方法。
答案 0 :(得分:0)
不是Zend_Server_Cache::factory()
,请尝试Zend_Cache::factory()