嗨,你能帮帮我吗!我想使用 zend 缓存文件,因为我在共享主机中。所以问题是我无法检索缓存的学说文件结果。数据已序列化,因为它是对象。$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());