Image 当我尝试缓存私有图像(带有修改的标题的操作)时,标题将被忽略

Image 当我尝试缓存私有图像(带有修改的标题的操作)时,标题将被忽略,image,zend-framework,caching,http-headers,zend-cache,Image,Zend Framework,Caching,Http Headers,Zend Cache,我有以下行动: public function viewImageAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $filename = sanitize_filename($this->_request->getParam('file'), 'jpg'); $dat

我有以下行动:

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/html
而不是
image/jpeg

我做错什么了吗

已编辑

我试过:

'memorize_headers' => array('Content-type')
但没什么

另外,我注意到这种类型的缓存(在应用程序启动之前)不能在管理区域上完成,因为应用程序需要运行和检查会话。因此,我需要尽快把查奇,以避免所有涉及组件的负荷


有什么建议吗?

解决方案

问题在于
memory_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))
);
此项的正确位置不在
默认\u选项中
键:

$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))
);

现在它可以工作了。

你能检查一个保存的缓存文件,看看它是否真的存储了标题吗?您应该能够找到名为“headers”
“…;s:7:“headers”;a:0:{}的序列化项}…
这是一个未保存头的示例。如果不保存头,则会出现另一个问题。如果保存头,则需要找出它们未被重放的原因。@darryl-e-clarke在元缓存文件中我有以下内容:
a:4:{s:4:“哈希”;I:1472989423;s:5:“mtime”;I:1290795482;s:6:“过期”;I:1290799082;s:4:“标记“;a:0:{}