0
我想嘗試創建像Zend的服務器Pagecache之類的東西。我想要實現的是存儲頁面輸出,所以我想這將是直接的HTML,但有可能將一些動態數據插入頁面。用動態佔位符實現全頁緩存的手段
我想嘗試創建像Zend的服務器Pagecache之類的東西。我想要實現的是存儲頁面輸出,所以我想這將是直接的HTML,但有可能將一些動態數據插入頁面。用動態佔位符實現全頁緩存的手段
輸出緩存是一個很大的問題。做對了,你需要考慮一下設計。
這裏有2種方法。代碼示例只是爲了解釋,它不是一個可行的解決方案。
class CachedController extends Zend_Action_Controller
{
public function indexAction()
{
$this->_view->leftBlock = $this->leftBlock();
$this->_view->rightBlock = $this->rightBlock();
}
protected function leftBlock()
{
// prepare left block, can use Zend_View if you like
// use Zend_Cache to cache the block
}
protected function rightBlock()
{
// prepare left block, can use Zend_View if you like
// use Zend_Cache to cache the block
}
}
/* VIEW SCRIPT */
<html>
<body>
<div class="left">
Left cached block here
<?php echo $this->leftBlock; ?>
</div>
<div class="main">
Do Your dynamic part here
</div>
<div class="right">
Right cached block here
<?php echo $this->rightBlock; ?>
</div>
</body>
</html>
您可以隨時使用ajax加載動態數據。 例如: 如果用戶登錄並要投票或什麼的。
這不適合,因爲頁面被分成大量的塊,例如我想要一段代碼在用戶交互過程中可用於更新。 – 2012-02-29 08:42:52