Skip to content

Commit 17cdadf

Browse files
tmotyledannenberg
authored andcommitted
[perf-OpenMage#918] Add runtime cache to Zend_Locale_Data
refs: OpenMage#917, OpenMage#979, OpenMage#1018
1 parent 765c39f commit 17cdadf

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

lib/Zend/Locale/Data.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class Zend_Locale_Data
7474
*/
7575
private static $_cacheDisabled = false;
7676

77+
/**
78+
* Internal cache, prevent repeated cache requests
79+
*
80+
* @var array
81+
*/
82+
private static $_localCache = array();
83+
7784
/**
7885
* Read the content from locale
7986
*
@@ -335,8 +342,15 @@ public static function getList($locale, $path, $value = false)
335342

336343
$val = urlencode($val);
337344
$id = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val);
345+
346+
// add runtime cache to avoid calling cache backend multiple times during one request
347+
if (isset(self::$_localCache[$id])) {
348+
return self::$_localCache[$id];
349+
}
338350
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
339-
return unserialize($result);
351+
$result = unserialize($result);
352+
self::$_localCache[$id] = $result;
353+
return $result;
340354
}
341355

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

948962
if (isset(self::$_cache)) {
963+
$data = serialize($temp);
949964
if (self::$_cacheTags) {
950-
self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
965+
self::$_cache->save( $data, $id, array('Zend_Locale'));
951966
} else {
952-
self::$_cache->save( serialize($temp), $id);
967+
self::$_cache->save( $data, $id);
953968
}
969+
static::$_localCache[$id] = $temp;
954970
}
955971

956972
return $temp;
@@ -984,8 +1000,15 @@ public static function getContent($locale, $path, $value = false)
9841000
}
9851001
$val = urlencode($val);
9861002
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
1003+
1004+
// add runtime cache to avoid calling cache backend multiple times during one request
1005+
if (isset(self::$_localCache[$id])) {
1006+
return self::$_localCache[$id];
1007+
}
9871008
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
988-
return unserialize($result);
1009+
$result = unserialize($result);
1010+
self::$_localCache[$id] = $result;
1011+
return $result;
9891012
}
9901013

9911014
switch(strtolower($path)) {
@@ -1499,11 +1522,13 @@ public static function getContent($locale, $path, $value = false)
14991522
$temp = current($temp);
15001523
}
15011524
if (isset(self::$_cache)) {
1525+
$data = serialize($temp);
15021526
if (self::$_cacheTags) {
1503-
self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
1527+
self::$_cache->save( $data, $id, array('Zend_Locale'));
15041528
} else {
1505-
self::$_cache->save( serialize($temp), $id);
1529+
self::$_cache->save( $data, $id);
15061530
}
1531+
static::$_localCache[$id] = $temp;
15071532
}
15081533

15091534
return $temp;

0 commit comments

Comments
 (0)