-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add runtime cache to Zend_Locale_Data #918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* | ||
|
@@ -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(); | ||
|
@@ -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; | ||
|
@@ -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))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw if I understand correctly lack of
before the Noticed that after the patch we anyway have many There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you propose a patch/pull request? thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #1018 |
||
return unserialize($result); | ||
$result = unserialize($result); | ||
self::$_localCache[$id] = $result; | ||
return $result; | ||
} | ||
|
||
switch(strtolower($path)) { | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmotyl
why this key used
'id'
?should it be the
$id
variable ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn, it should. Can you make a PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and in line 1526 too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one reason, why its always good to wait for a second Review 👀