我在與Zend_Navigation的頁面層次結構麻煩,當我緩存它使用Zend_Cache是越來越混亂。Zend_Navigation緩存
背景:我有大約50頁,約300種產品存儲在數據庫中。我查詢數據庫並創建一個數組來提供給Zend_Navigation。
緩存是
$secondsBetweenRefreshes = APPLICATION_ENV == 'development' ? 30 : 300;
self::$cache = Zend_Cache::factory('Core', 'File',
array('automatic_serialization' => true,
'lifetime' => $secondsBetweenRefreshes),
array('cache_dir' => CACHE_PATH . 'nav/')
);
這工作得很好
$struct = $cache->load('Zend_Navigation');
if (empty($struct))
{
$cache->save($struct = self::getSiteStructure());
}
return new Zend_Navigation($struct);
這被擾亂如果不從緩存中拉
$struct = $cache->load('Zend_Navigation');
if (empty($struct))
{
$cache->save($struct = new Zend_Navigation(self::getSiteStructure());
}
return $struct;
導航工作正常。是的,顯而易見的解決方案是不緩存Zend_Navigation,但構造函數做了很多工作來構建其內部表示:有意義的做緩存與儘可能多的預先計算,因爲我可以...
我'米仍然試圖查看是否有一個模式的混亂結果。樹中沒有循環/循環。
感謝。發現。查看代碼,他們使用spl_object_hash()http://nz.php.net/manual/en/function.spl-object-hash.php來計算容器內頁面的散列鍵。在反序列化()時顯然會搞砸了。 所以答案是使用toArray()。但是如果您從Bootstrap緩存,則會出現更多問題。答案似乎是創建一個控制器動作助手並按需加載它。 – Steve 2009-10-06 07:16:58