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/htmlnot image/jpeg

难道我做错了什么?

已编辑

我试过了:

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

但没什么...

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

有小费吗?

4

1 回答 1

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

现在它起作用了。

于 2010-11-26T19:28:11.993 回答