Module: nagvis Branch: master Commit: 000b013e85f7ffd6a19f9f1dabeb24915f611bf3 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=000b013e85f7ffd6a19f9f1dabeb24915f611bf3
Author: Lars Michelsen <[email protected]> Date: Tue May 4 00:19:21 2010 +0200 Added small language cache method to prevent double fetching language strings at a central place - runtime improvement --- share/server/core/classes/GlobalLanguage.php | 9 +++++++++ .../core/classes/objects/NagVisStatefulObject.php | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/share/server/core/classes/GlobalLanguage.php b/share/server/core/classes/GlobalLanguage.php index 88ad0e8..16ad115 100644 --- a/share/server/core/classes/GlobalLanguage.php +++ b/share/server/core/classes/GlobalLanguage.php @@ -31,6 +31,7 @@ class GlobalLanguage { private $textDomain; private $sCurrentLanguage; private $sCurrentEncoding; + private $cache = Array(); /** * Class Constructor @@ -244,6 +245,10 @@ class GlobalLanguage { * @author Lars Michelsen <[email protected]> */ public function getText($id, $replace = NULL) { + // Use cache if available + if(isset($this->cache[$id])) + return $this->cache[$id]; + $ret = $this->getTextOfId($id); if($replace !== NULL) { @@ -262,6 +267,10 @@ class GlobalLanguage { $ret .= 'Opts: '.json_encode($replace); } } + + // Store in cache for this page processing + if(!isset($this->cache[$id])) + $this->cache[$id] = $ret; return $ret; } diff --git a/share/server/core/classes/objects/NagVisStatefulObject.php b/share/server/core/classes/objects/NagVisStatefulObject.php index 5db05d3..a42e637 100644 --- a/share/server/core/classes/objects/NagVisStatefulObject.php +++ b/share/server/core/classes/objects/NagVisStatefulObject.php @@ -51,6 +51,7 @@ class NagVisStatefulObject extends NagVisObject { protected static $iconPath = null; protected static $iconHtmlPath = null; + protected static $langChildStates = null; protected $dateFormat; @@ -828,17 +829,18 @@ class NagVisStatefulObject extends NagVisObject { * @author Lars Michelsen <[email protected]> */ protected function mergeSummaryOutput($arrStates, $objLabel) { - $this->summary_output .= $this->CORE->getLang()->getText('childStatesAre').' '; - foreach($arrStates AS $state => &$num) { + if(NagVisStatefulObject::$langChildStates === null) + NagVisStatefulObject::$langChildStates = $this->CORE->getLang()->getText('childStatesAre'); + + $this->summary_output .= NagVisStatefulObject::$langChildStates.' '; + foreach($arrStates AS $state => $num) { if($num > 0) { $this->summary_output .= $num.' '.$state.', '; } } // Remove last comma - $this->summary_output = preg_replace('/, $/', '', $this->summary_output); - - $this->summary_output .= ' '.$objLabel.'.'; + $this->summary_output = rtrim($this->summary_output, ', ').' '.$objLabel.'.'; } /** ------------------------------------------------------------------------------ _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
