unserialize cache zend doctrine2

时间:2012-05-25 04:40:09

标签: zend-framework serialization doctrine-orm

你能帮帮我吗?我想在共享主机中使用zend缓存文件。 所以问题是我无法检索缓存的doctrine文件结果。数据已经序列化,因为它是对象。 $ cache-> load($ id)返回数组我无法反序列化。 如果你能帮助我或提出建议,我会很高兴的。这是我的代码。

$request    = $this->getRequest();
$slug   = $request->getParam('slug');

$front  = Zend_Controller_Front::getInstance();
$bootstrap= $front->getParam('bootstrap');

$cache = $bootstrap->getResource('cachemanager')->getCache('content');

$cacheId   = md5('news_' . $slug);
if ( !($news = **unserialize($cache->load($cacheId))**) ) {

$news   = $this->_em->getRepository('Custom\Entity\News')
              ->findOneBySlug($slug);
    $cache->save($news, $cacheId);
var_dump('if u see me that mean not from cached');
 }

 $page = new Zend_Navigation_Page_Mvc(array(  
        'label'         => $news[0]->getTitle(),
        'route'     => 'news-view',
    'module'        => 'news',
    'controller'    => 'index',
    'action'        => 'view',
    'params'        => array(
        'slug' => $news[0]->getAlias())
        )
  );
 $page->setActive(false);
 $this->_helper->navigation->getContainer()
              ->findOneBy('uri', '/category/' . $news[0]->getCategory()->getSlug())
              ->addPage($page);

 $this->view->ogpa = new OpenGraphProtocolArticle();
 $this->view->news   = $news;
 $this->view->headTitle($news[0]->getTitle());

1 个答案:

答案 0 :(得分:0)

不要在Zend_Cache中保存任何Doctrine2模型,请参阅:https://ssmusoke.com/2012/03/25/doctrine2-day-3-proxies-associations-relationships/

这是因为在后台Doctrine2使用了Zend自动加载器无法反序列化的代理类,这会让你感到非常悲痛......

如果要缓存任何内容,请缓存输出而不是模型。

相关问题