2010-11-25 31 views
3

我有以下作用:當我嘗試緩存私有映像(與體改頭動作),頭被省略

public function viewImageAction() 
{ 
    $this->_helper->layout()->disableLayout(); 
    $this->_helper->viewRenderer->setNoRender(); 

    $filename = sanitize_filename($this->_request->getParam('file'), 'jpg'); 
    $data = file_get_contents(APPLICATION_PATH . '/../private-files/fans-pictures/' . $filename); 
    $this->getResponse() 
     ->setHeader('Content-type', 'image/jpeg') 
     ->setBody($data); 
} 

而在我的index.php申請前開始,我有:

/** Zend Cache to avoid unecessary application load **/ 
require_once 'Zend/Cache.php'; 

$frontendOptions = array(
'lifetime' => 3600, 
'default_options' => array(
    'cache' => $cache_flag, 
    'cache_with_cookie_variables' => true, 
    'make_id_with_cookie_variables' => false), 
'regexps' => array(
    '^(/.+)?/admin/?' => array('cache' => false), 
    '^(/.+)?/pictures/view-image/?' => array('cache' => true), 
    '^(/.+)?/authentication/?' => array('cache' => false), 
    '^(/.+)?/fan-profile/?' => array('cache' => false), 
    '^(/.+)?/fan-registration/?' => array('cache' => false)) 
); 

$backendOptions = array(
'cache_dir' => APPLICATION_PATH . '/cache/pages/'); 

$cache = Zend_Cache::factory(
    'Page', 'File', $frontendOptions, $backendOptions 
); 

$cache->start(); 

緩存工作正常,但如果我嘗試訪問的URL,像public/admin/pictures/view-image/file/63.jpg頭配備text/htmlimage/jpeg

我做錯了什麼?

EDITED

我已經試過:

'memorize_headers' => array('Content-type') 

但沒有......

而且,我已經注意這個緩存類型(應用程序開始之前)就可以不會在管理區域完成,因爲應用程序需要運行並檢查會話。所以我需要儘快把chache放在一起,以避免涉及所有組件的負載。

任何提示?

+0

你可以檢查一個保存的緩存文件,看看它是否實際存儲頭文件?你應該能夠找到一個名爲'headers'的序列化項'「...; s:7:」headers「; a:0:{}} ...這是一個沒有頭文件保存的例子。不保存它們,還有另一個問題,如果是保存它們,那麼這就是爲什麼它們沒有被重放的問題。 – 2010-11-25 21:43:31

回答

1

SOLUTION

的問題是與memorize_headers參數的位置。

我是想這樣的:

$frontendOptions = array(
'lifetime' => 3600, 
'default_options' => array(
    'cache' => $cache_flag, 
    'cache_with_cookie_variables' => true, 
    'memorize_headers' => array('Content-Type', 'Content-Encoding'), 
    'make_id_with_cookie_variables' => false), 
'regexps' => array(
    '^(/.+)?/admin/?' => array('cache' => false), 
    '^(/.+)?/admin/pictures/view-image/?' => array('cache' => true), 
    '^(/.+)?/authentication/?' => array('cache' => false), 
    '^(/.+)?/fan-profile/?' => array('cache' => false), 
    '^(/.+)?/fan-registration/?' => array('cache' => false)) 
); 

這樣做的正確的位置是出了default_options關鍵的:

$frontendOptions = array(
'lifetime' => 3600, 
'memorize_headers' => array('Content-Type', 'Content-Encoding'), 
'default_options' => array(
    'cache' => $cache_flag, 
    'cache_with_cookie_variables' => true, 
    //'cache_with_session_variables' => true, 
    'make_id_with_cookie_variables' => false), 
'regexps' => array(
    '^(/.+)?/admin/?' => array('cache' => false), 
    '^(/.+)?/admin/pictures/view-image/?' => array('cache' => true), 
    '^(/.+)?/authentication/?' => array('cache' => false), 
    '^(/.+)?/fan-profile/?' => array('cache' => false), 
    '^(/.+)?/fan-registration/?' => array('cache' => false)) 
); 

現在,它的工作原理。