Skip to content

Commit

Permalink
[perf-OpenMage#918] Add runtime cache to Zend_Locale_Data
Browse files Browse the repository at this point in the history
  • Loading branch information
tmotyl authored and edannenberg committed Aug 17, 2020
1 parent 765c39f commit 17cdadf
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 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 calling 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] = $temp;
}

return $temp;
Expand Down Expand Up @@ -984,8 +1000,15 @@ public static function getContent($locale, $path, $value = false)
}
$val = urlencode($val);
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);

// add runtime cache to avoid calling 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;
}

switch(strtolower($path)) {
Expand Down Expand Up @@ -1499,11 +1522,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] = $temp;
}

return $temp;
Expand Down

0 comments on commit 17cdadf

Please sign in to comment.