Skip to content

Commit

Permalink
Add runtime cache to Zend_Locale_Data (#918)
Browse files Browse the repository at this point in the history
Fixes: #917
  • Loading branch information
tmotyl authored Apr 21, 2020
1 parent f3046cf commit 48939f0
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions lib/Zend/Locale/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class Zend_Locale_Data
*/
private static $_cacheDisabled = false;

/**
* Internal cache, prevent repeated cache requests
*
* @var array
*/
private static $_localCache = array();

/**
* Read the content from locale
*
Expand Down Expand Up @@ -335,8 +342,15 @@ public static function getList($locale, $path, $value = false)

$val = urlencode($val);
$id = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val);

// add runtime cache to avoid callng cache backend multiple times during one request
if ( isset(self::$_localCache[$id])) {
return self::$_localCache[$id];
}
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
return unserialize($result);
$result = unserialize($result);
self::$_localCache[$id] = $result;
return $result;
}

$temp = array();
Expand Down Expand Up @@ -946,11 +960,13 @@ public static function getList($locale, $path, $value = false)
}

if (isset(self::$_cache)) {
$data = serialize($temp);
if (self::$_cacheTags) {
self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
self::$_cache->save( $data, $id, array('Zend_Locale'));
} else {
self::$_cache->save( serialize($temp), $id);
self::$_cache->save( $data, $id);
}
static::$_localCache['id'] = $data;
}

return $temp;
Expand Down Expand Up @@ -985,7 +1001,9 @@ public static function getContent($locale, $path, $value = false)
$val = urlencode($val);
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
return unserialize($result);
$result = unserialize($result);
self::$_localCache[$id] = $result;
return $result;
}

switch(strtolower($path)) {
Expand Down Expand Up @@ -1499,11 +1517,13 @@ public static function getContent($locale, $path, $value = false)
$temp = current($temp);
}
if (isset(self::$_cache)) {
$data = serialize($temp);
if (self::$_cacheTags) {
self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
self::$_cache->save( $data, $id, array('Zend_Locale'));
} else {
self::$_cache->save( serialize($temp), $id);
self::$_cache->save( $data, $id);
}
static::$_localCache['id'] = $data;
}

return $temp;
Expand Down

0 comments on commit 48939f0

Please sign in to comment.