Index: trunk/core/kernel/application.php =================================================================== diff -u -N -r4133 -r4135 --- trunk/core/kernel/application.php (.../application.php) (revision 4133) +++ trunk/core/kernel/application.php (.../application.php) (revision 4135) @@ -339,8 +339,7 @@ $this->registerClass('kArray', KERNEL_PATH.'/utility/params.php'); $this->registerClass('Params', KERNEL_PATH.'/utility/params.php'); - $this->registerClass('Params', KERNEL_PATH.'/utility/params.php', 'kFilenamesCache'); - + $this->registerClass('kCache', KERNEL_PATH.'/utility/cache.php', 'Cache', Array('Params')); $this->registerClass('kHTTPQuery', KERNEL_PATH.'/utility/http_query.php', 'HTTPQuery', Array('Params') ); $this->registerClass('Session', KERNEL_PATH.'/session/session.php'); @@ -401,19 +400,58 @@ */ function getFilename($prefix, $id) { - $field = ($prefix == 'c') ? 'NamedParentPath' : 'Filename'; - $filenames_cache =& $this->recallObject('kFilenamesCache'); - $filename = $filenames_cache->Get($prefix.'_'.$id); - if($filename === false) - { + $filename = $this->getCache('filenames', $prefix.'_'.$id); + if ($filename === false) { $table = $this->getUnitOption($prefix, 'TableName'); $id_field = $this->getUnitOption($prefix, 'IDField'); - $sql = 'SELECT '.$field.' FROM '.$table.' WHERE '.$id_field.' = '.$this->DB->qstr($id); - $filename = $this->DB->GetOne($sql); - $filenames_cache->Set($prefix.'_'.$id, $filename); + + if ($prefix == 'c') { + // this allows to save 2 sql queries for each category + $sql = 'SELECT NamedParentPath, CachedCategoryTemplate, CachedItemTemplate + FROM '.$table.' + WHERE '.$id_field.' = '.$this->DB->qstr($id); + $category_data = $this->DB->GetRow($sql); + $filename = $category_data['NamedParentPath']; + $this->setCache('category_templates', $id, $category_data['CachedCategoryTemplate']); + $this->setCache('item_templates', $id, $category_data['CachedItemTemplate']); + } + else { + $sql = 'SELECT Filename + FROM '.$table.' + WHERE '.$id_field.' = '.$this->DB->qstr($id); + $filename = $this->DB->GetOne($sql); + } + $this->setCache('filenames', $prefix.'_'.$id, $filename); } return $filename; } + + + /** + * Adds new value to cache $cache_name and identified by key $key + * + * @param string $cache_name cache name + * @param int $key key name to add to cache + * @param mixed $value value of chached record + */ + function setCache($cache_name, $key, $value) + { + $cache =& $this->recallObject('Cache'); + $cache->setCache($cache_name, $key, $value); + } + + /** + * Returns cached $key value from cache named $cache_name + * + * @param string $cache_name cache name + * @param int $key key name from cache + * @return mixed + */ + function getCache($cache_name, $key) + { + $cache =& $this->recallObject('Cache'); + return $cache->getCache($cache_name, $key); + } /** * Defines default constants if it's not defined before - in config.php @@ -543,7 +581,12 @@ $this->Phrases->UpdateCache(); flush(); - + + if ($this->isDebugMode() && dbg_ConstOn('DBG_CACHE')) { + $cache =& $this->recallObject('Cache'); + $cache->printStatistics(); + } + $event_manager =& $this->recallObject('EventManager'); $event_manager->RunRegularEvents(reAFTER); @@ -584,13 +627,14 @@ * Returns variable passed to the script as GET/POST/COOKIE * * @access public - * @param string $var Variable name + * @param string $name Name of variable to retrieve + * @param int $default default value returned in case if varible not present * @return mixed */ - function GetVar($var, $mode = FALSE_ON_NULL) + function GetVar($name, $default = false) { $http_query =& $this->recallObject('HTTPQuery'); - return $http_query->Get($var, $mode); + return $http_query->Get($name, $default); } /**