|
|
@@ -59,6 +59,13 @@ abstract class Zend_Translate_Adapter {
|
|
|
protected static $_cache = null;
|
|
|
|
|
|
/**
|
|
|
+ * Internal value to remember if cache supports tags
|
|
|
+ *
|
|
|
+ * @var boolean
|
|
|
+ */
|
|
|
+ private static $_cacheTags = false;
|
|
|
+
|
|
|
+ /**
|
|
|
* Scans for the locale within the name of the directory
|
|
|
* @constant integer
|
|
|
*/
|
|
|
@@ -82,6 +89,7 @@ abstract class Zend_Translate_Adapter {
|
|
|
* 'logUntranslated' => when true, untranslated messages are not logged
|
|
|
* 'reload' => reloads the cache by reading the content again
|
|
|
* 'scan' => searches for translation files using the LOCALE constants
|
|
|
+ * 'tag' => tag to use for the cache
|
|
|
*
|
|
|
* @var array
|
|
|
*/
|
|
|
@@ -96,7 +104,8 @@ abstract class Zend_Translate_Adapter {
|
|
|
'logUntranslated' => false,
|
|
|
'reload' => false,
|
|
|
'route' => null,
|
|
|
- 'scan' => null
|
|
|
+ 'scan' => null,
|
|
|
+ 'tag' => 'Zend_Translate'
|
|
|
);
|
|
|
|
|
|
/**
|
|
|
@@ -347,7 +356,11 @@ abstract class Zend_Translate_Adapter {
|
|
|
|
|
|
if (isset(self::$_cache) and ($change == true)) {
|
|
|
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
|
|
- self::$_cache->save($this->_options, $id);
|
|
|
+ if (self::$_cacheTags) {
|
|
|
+ self::$_cache->save($this->_options, $id, array($this->_options['tag']));
|
|
|
+ } else {
|
|
|
+ self::$_cache->save($this->_options, $id);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $this;
|
|
|
@@ -435,7 +448,11 @@ abstract class Zend_Translate_Adapter {
|
|
|
|
|
|
if (isset(self::$_cache)) {
|
|
|
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
|
|
- self::$_cache->save($this->_options, $id);
|
|
|
+ if (self::$_cacheTags) {
|
|
|
+ self::$_cache->save($this->_options, $id, array($this->_options['tag']));
|
|
|
+ } else {
|
|
|
+ self::$_cache->save($this->_options, $id);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -644,7 +661,11 @@ abstract class Zend_Translate_Adapter {
|
|
|
|
|
|
if (($read) and (isset(self::$_cache))) {
|
|
|
$id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
|
|
|
- self::$_cache->save($temp, $id);
|
|
|
+ if (self::$_cacheTags) {
|
|
|
+ self::$_cache->save($temp, $id, array($this->_options['tag']));
|
|
|
+ } else {
|
|
|
+ self::$_cache->save($temp, $id);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $this;
|
|
|
@@ -885,6 +906,7 @@ abstract class Zend_Translate_Adapter {
|
|
|
public static function setCache(Zend_Cache_Core $cache)
|
|
|
{
|
|
|
self::$_cache = $cache;
|
|
|
+ self::_getTagSupportForCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -914,12 +936,21 @@ abstract class Zend_Translate_Adapter {
|
|
|
/**
|
|
|
* Clears all set cache data
|
|
|
*
|
|
|
+ * @param string $tag Tag to clear when the default tag name is not used
|
|
|
* @return void
|
|
|
*/
|
|
|
- public static function clearCache()
|
|
|
+ public static function clearCache($tag = null)
|
|
|
{
|
|
|
require_once 'Zend/Cache.php';
|
|
|
- self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
|
|
|
+ if (self::$_cacheTags) {
|
|
|
+ if ($tag == null) {
|
|
|
+ $tag = 'Zend_Translate';
|
|
|
+ }
|
|
|
+
|
|
|
+ self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array($tag));
|
|
|
+ } else {
|
|
|
+ self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -928,4 +959,22 @@ abstract class Zend_Translate_Adapter {
|
|
|
* @return string
|
|
|
*/
|
|
|
abstract public function toString();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Internal method to check if the given cache supports tags
|
|
|
+ *
|
|
|
+ * @param Zend_Cache $cache
|
|
|
+ */
|
|
|
+ private static function _getTagSupportForCache()
|
|
|
+ {
|
|
|
+ $backend = self::$_cache->getBackend();
|
|
|
+ if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) {
|
|
|
+ $cacheOptions = $backend->getCapabilities();
|
|
|
+ self::$_cacheTags = $cacheOptions['tags'];
|
|
|
+ } else {
|
|
|
+ self::$_cacheTags = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::$_cacheTags;
|
|
|
+ }
|
|
|
}
|