ZF-4993: Zend_Translate doesn't use cache properly

Description

When using cache on the Zend_Translate it seems to be writing to cache all the time although it has saved and valid cache. I'm using Core as front cache and Memcached as backend cache;

This is just a part of logged flow of cahce read and save - CACHE READ ID Zend_Translate_Gettext_Options - CACHE SAVED ID Zend_Translate_Gettext_Options - CACHE SAVED ID Zend_Translate_Gettext_Options - CACHE SAVED ID Zend_Translate_Gettext_Options

When translation adapter gets instanced the cache gets read inside constructor but some methods get also invoked that unconditionally write down the same cache that was previously read.

Comments

Without any additional data there is no way to reproduce this behaviour of your environment.

Actually the options cache is only wrote in two places:

  • When options are set
  • When another locale is set

As you gave no details there can actually no failure be located.

Not reproducable.

Multi cache access for example possible by using file search or adding files.

Well this is the code that wirtes that Options into cache.

$lngPath = '/path/to/languages/en_US/LC_MESSAGES/global.mo';
$cacheDir = '/path/to/writable/cache';

$frontendOptions = array(
    'lifetime'                  => 7200,
    'automatic_serialization'   => true,
    //'logging' => true,
);

$backendOptions = array(
    'cache_dir' => $cacheDir,
);

$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Translate::setCache($cache);
$translate = new Zend_Translate('gettext', $lngPath, 'en');

Constructor of the Zend_Translate_Adapter class reads options from the cache (let's say this is second run and there is something in the cache). Then it calls setLocale() method. setLocale() writes down the same options to cache again. addTranslation() does similar things ...

MY ZF version is 1.7.0 downloaded from the site.

A small change has been made with r12713 which will write to cache only when the options differs from before even if setOption is called.

Still, it is not possible to erase this behaviour completly because files are searched through when using directory search and the options are changed dynamically. This will always lead to a cache save.