看看这段代码:
$cache = Zend_Cache::factory('Output',
'File',
$frontendOptions,
$backendOptions);
// we pass a unique identifier to the start() method
if(!$cache->start('mypage')) {
// output as usual:
echo 'Hello world! ';
echo 'This is cached ('.time().') ';
$cache->end(); // the output is saved and sent to the browser
}
正如本文档所解释的,如果已经处理了上述内容,则不会进入块语句,因此时间不会刷新。假设过期时间配置为 30 秒。
访客 A 出现并缓存输出,因此很明显,访客将看到相同的时间进行多次刷新 30 秒。我的问题是,如果访客 B 同时出现,他会看到与访客 A 相同的时间,因为它已经缓存或缓存将是特定于用户的?
是的,他会的,因为这就是人们应该使用缓存的原因:不要一遍又一遍地为每个用户处理东西。您可以使用用户特定的内容创建缓存 ID
$cache->start('mypage'.$userId);
但是,您应该问问自己是否真的值得缓存。