0

我有这个代码:

'translator'  => array(
...
'cache' => array(
    'adapter' => array(
        'name'    => 'Filesystem',
        'options' => array(
            'cache_dir' => __DIR__ . '/../../../data/cache',
            'ttl'       => '3600'
        )
    ),
    'plugins' => array(
        array(
            'name'    => 'serializer',
            'options' => array()
        ),
        'exception_handler' => array(
            'throw_exceptions' => true
        )
    )
)

问题是,我如何不通过 TTL 使其无效?

例如,我知道何时更改了翻译,因此我想按需使其无效,但我还没有找到方法。

4

3 回答 3

1

The translator component does not utilize the TaggableInterface so you have to know the cacheId which the translator generates to clear the item from you storage adapter. You can use the following code to simply generate the same id and remove the item. Call this from your service or some event listener.

$translator = $sm->get('McvTranslator');
$textDomain = 'default';
$locale = 'en';

$cacheId = 'Zend_I18n_Translator_Messages_' . md5($textDomain . $locale);
$translator->getCache()->removeItem($cacheId);
于 2013-10-14T16:27:14.000 回答
0

另一种方法是:在代码中找到调用addTranslation.

例如:

$translate = Zend_Registry::get('Zend_Translate');
$translate->addTranslation(array(
            'content' => "$dir/$locale.mo",
            'locale' => $locale
        ));

将函数更改addTranslation为 add reload => true,如下所示:

$translate->addTranslation(array(
            'content' => "$dir/$locale.mo",
            'locale' => $locale,
        'reload' => true
        ));

刷新您的页面。瞧。记得在那之后删除reload,否则你将没有缓存。

于 2014-05-22T14:42:23.190 回答
0

我认为您可以设置 Ttl = 0 (始终),并且当缓存(文件)不再有效时 - 将其删除。

于 2013-10-14T10:59:18.977 回答