Zend_Cache是
我可能会使用Zend Frameworks Zend_Cache库.
您可以使用此组件而无需使用整个框架.
下载核心文件后,您需要在项目中包含Zend_Cache.
Zend_Cache docs.
您是否已决定如何缓存数据?你在使用文件系统吗?或者你是memcache?一旦知道了要使用的内容,就需要使用特定的Zend_Cache后端.
Zend_Cache后端/ Zend_Cache前端
>您需要使用后端(如何在存储中缓存您想要缓存的内容)和
>你需要使用一个前端(你如何实际想要缓存…比如使用缓冲区,或者缓存函数结果等)
所以你会做这样的事……
// configure caching backend strategy
$backend = new Zend_Cache_Backend_Memcached(
array(
'servers' => array( array(
'host' => '127.0.0.1',
'port' => '11211'
) ),
'compression' => true
) );
// configure caching frontend strategy
$frontend = new Zend_Cache_Frontend_Output(
array(
'caching' => true,
'cache_id_prefix' => 'myApp',
'write_control' => true,
'automatic_serialization' => true,
'ignore_user_abort' => true
) );
// build a caching object
$cache = Zend_Cache::factory( $frontend, $backend );
这将创建一个使用Zend_Cache_Frontend_Output缓存机制的缓存.
要使用你想要的Zend_Cache_Frontend_Output,它将是simple.你将使用输出而不是核心.您传递的选项是相同的.然后使用它你会:
Zend_Cache_Frontend_Output – 用法
// if it is a cache miss, output buffering is triggered
if (!($cache->start('mypage'))) {
// output everything as usual
echo 'Hello world! ';
echo 'This is cached ('.time().') ';
$cache->end(); // output buffering ends
}
echo 'This is never cached ('.time().').';
对不起,这个问题花了比预期更长的时间,写了很多答案!