diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-03-07 04:44:16 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-03-07 04:44:16 +0000 |
commit | 3356091b65eea9fc5902e2b9b41b3adbda991f94 (patch) | |
tree | b96d079c8e308ec25c9d08bcb9fe50d1c6e1b46c /core/helpers | |
parent | e96e26a12f578d46183b60c3b2cfd69ffe52ed16 (diff) |
Add in-request caching of vars that we've already looked up. We're
still doing too many database queries, but this cuts down some dupes.
Diffstat (limited to 'core/helpers')
-rw-r--r-- | core/helpers/module.php | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/core/helpers/module.php b/core/helpers/module.php index 0d43c248..190cec73 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -26,6 +26,7 @@ class module_Core { public static $module_names = array(); public static $modules = array(); + public static $var_cache = array(); static function get_version($module_name) { return ORM::factory("module")->where("name", $module_name)->find()->version; @@ -217,11 +218,17 @@ class module_Core { * @return the value */ static function get_var($module_name, $name, $default_value=null) { + if (isset(self::$var_cache[$module_name][$name])) { + return self::$var_cache[$module_name][$name]; + } + $var = ORM::factory("var") ->where("module_name", $module_name) ->where("name", $name) ->find(); - return $var->loaded ? $var->value : $default_value; + + self::$var_cache[$module_name][$name] = $var->loaded ? $var->value : $default_value; + return self::$var_cache[$module_name][$name]; } /** |