PHP页面运行一半,在PHP中仅缓存页面的一部分

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().').';

对不起,这个问题花了比预期更长的时间,写了很多答案!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值