我有以下行动:
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();
缓存工作正常,但如果我尝试访问该网址,例如public/admin/pictures/view-image/file/63.jpg
,则标头会text/html
而不是image/jpeg
。
我做错了吗?
EDITED
我试过了:
'memorize_headers' => array('Content-type')
但没有......
另外,我注意到这种类型的缓存(在应用程序启动之前)无法在管理区域完成,因为应用程序需要运行并检查会话。所以我需要尽快放置chache以避免所有组件的负载。
任何提示?
答案 0 :(得分:1)
<强>解强>
问题在于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))
);
现在可行。