From a5be2218dcd89eeb230be6e58db25a2fe4660707 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Tue, 2 Oct 2018 07:59:41 +1000 Subject: [PATCH] Added extra layer of caching / reduce load on Redis Zend_Locale_Data returns a formatted locale string based on the input. Once string is proceed it stored into cache storage File or Redis or Memcache or MySQL. Every time someone is asking for the same formatted locale string, it will get it from cache. However, if the same execution is asking for the same locale string, it always looking into the cache storage. Ideally, we can store result in temporary variable to reduce the load on remote cache storage. Example: - There is a booking website - There are number of providers who have their open hours - Zend_Date function is in use to present data in correct locale - Open hour from each provider going via Zend_Date function to display the right date / locale. - Page has about 20-50 providers, in some cases, the number of calls to cache storage (e.g. Redis) could jump to 22,000+ on page load. This commit introduced a temporary variable to store a cache for a single page load. --- library/Zend/Locale/Data.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/library/Zend/Locale/Data.php b/library/Zend/Locale/Data.php index c4331abd73..ed567c00fa 100644 --- a/library/Zend/Locale/Data.php +++ b/library/Zend/Locale/Data.php @@ -335,10 +335,15 @@ public static function getList($locale, $path, $value = false) $val = urlencode($val); $id = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val); - if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { - return unserialize($result); + if (!self::$_cacheDisabled && !empty(self::$_list[$id])) { + return self::$_list[$id]; } + if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { + self::$_list[$id] = unserialize($result); + return self::$_list[$id]; + } + $temp = array(); switch(strtolower($path)) { case 'language': @@ -984,8 +989,13 @@ public static function getContent($locale, $path, $value = false) } $val = urlencode($val); $id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val); + if (!self::$_cacheDisabled && !empty(self::$_list[$id])) { + return self::$_list[$id]; + } + if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { - return unserialize($result); + self::$_list[$id] = unserialize($result); + return self::$_list[$id]; } switch(strtolower($path)) {