Index: trunk/core/kernel/startup.php
===================================================================
diff -u -r3863 -r4135
--- trunk/core/kernel/startup.php (.../startup.php) (revision 3863)
+++ trunk/core/kernel/startup.php (.../startup.php) (revision 4135)
@@ -92,9 +92,6 @@
// up to here
// global constants
- define ('FALSE_ON_NULL', 1);
- define ('EMPTY_ON_NULL', 2);
-
define ('KG_TO_POUND', 2.20462262);
define ('POUND_TO_KG', 0.45359237);
Index: trunk/core/kernel/utility/cache.php
===================================================================
diff -u
--- trunk/core/kernel/utility/cache.php (revision 0)
+++ trunk/core/kernel/utility/cache.php (revision 4135)
@@ -0,0 +1,89 @@
+Conn =& $this->Application->GetADODBConnection();
+
+ $this->debugCache = $this->Application->isDebugMode() && dbg_ConstOn('DBG_CACHE');
+ }
+
+ /**
+ * 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->Get($cache_name, Array());
+ $cache[$key] = $value;
+ $this->Set($cache_name, $cache);
+ }
+
+ /**
+ * 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->Get($cache_name, Array());
+ $ret = getArrayValue($cache, $key);
+
+ $this->setStatistics($cache_name, $key, $ret);
+
+ return $ret;
+ }
+
+ function setStatistics($cache_name, $key, $found)
+ {
+ if (!$this->debugCache) return true;
+
+ if (!isset($this->statistics[$cache_name])) {
+ $this->statistics[$cache_name] = Array();
+ }
+
+ if (!isset($this->statistics[$cache_name][$key])) {
+ $this->statistics[$cache_name][$key] = Array();
+ }
+
+ $status_key = $found ? 'found' : 'not_found';
+ if (!isset($this->statistics[$cache_name][$key][$status_key])) {
+ $this->statistics[$cache_name][$key][$status_key] = 0;
+ }
+
+ $this->statistics[$cache_name][$key][$status_key]++;
+ }
+
+ function printStatistics()
+ {
+ foreach ($this->statistics as $cache_name => $cache_data) {
+ foreach ($cache_data as $key => $value) {
+ if (!isset($value['found']) || $value['found'] == 1) {
+ // remove cached records, that were used only 1 or 2 times
+ unset($this->statistics[$cache_name][$key]);
+ }
+ }
+ }
+
+ print_pre($this->statistics);
+ }
+ }
+
+?>
\ No newline at end of file
Index: trunk/core/kernel/application.php
===================================================================
diff -u -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);
}
/**
Index: trunk/tools/debug_sample.php
===================================================================
diff -u -r4101 -r4135
--- trunk/tools/debug_sample.php (.../debug_sample.php) (revision 4101)
+++ trunk/tools/debug_sample.php (.../debug_sample.php) (revision 4135)
@@ -29,6 +29,7 @@
define('DBG_PHRASES', 1); // Add ability to translate phrases on the fly (K4 only)
define('DBG_WINDOW_WIDTH', 700);// Set custom debugger layer width (in pixels)
+ define('DBG_CACHE', 1); // debug cache usage
// define('DBG_REDIRECT', 1);
// define('DBG_ZEND_PRESENT',0);
//define('DBG_VALIDATE_CONFIGS',1); // check that config fields match ones from database
Index: trunk/core/kernel/utility/params.php
===================================================================
diff -u -r3330 -r4135
--- trunk/core/kernel/utility/params.php (.../params.php) (revision 3330)
+++ trunk/core/kernel/utility/params.php (.../params.php) (revision 4135)
@@ -3,7 +3,7 @@
class Params extends kBase {
var $_Params = Array();
- function Params($params_str=null)
+ function Params($params_str = null)
{
parent::kBase();
if($params_str != '') $this->SplitParamsStr($params_str);
@@ -35,8 +35,6 @@
*/
function Set($name, $val)
{
- //echo "sessing params: [$name] = [$val] (class: ".get_class($this).")
";
-// $this->_Params[strtolower($name)] = $val;
$this->_Params[$name] = $val;
}
@@ -54,19 +52,14 @@
/**
* Gets parameter value by parameter name
*
- * @param string $name
- * @param int $mode
+ * @param string $name Name of variable to retrieve
+ * @param int $default default value returned in case if varible not present
* @return string
* @access public
*/
- function Get($name, $mode=FALSE_ON_NULL)
+ function Get($name, $default = false)
{
- // echo " name : '$name' || mode : $mode
";
- //$name = strtolower($name);
- if (array_key_exists($name, $this->_Params))
- return $this->_Params[$name];
- else
- return $mode == FALSE_ON_NULL ? false : '';
+ return isset($this->_Params[$name]) ? $this->_Params[$name] : $default;
}
/**
Index: trunk/core/units/general/main_event_handler.php
===================================================================
diff -u -r4133 -r4135
--- trunk/core/units/general/main_event_handler.php (.../main_event_handler.php) (revision 4133)
+++ trunk/core/units/general/main_event_handler.php (.../main_event_handler.php) (revision 4135)
@@ -30,9 +30,6 @@
*/
function BuildEnv(&$event)
{
- static $ThemesCache = array();
- static $LangCache = array();
-
$prefix_special = $event->getPrefixSpecial();
$url_params = $event->getEventParam('url_params');
@@ -60,27 +57,33 @@
$default_language_id = $this->Application->GetDefaultLanguageId();
if( $processed_params['m_lang'] != $default_language_id )
{
- if (!isset($LangCache[$processed_params['m_lang']])) {
- $LangCache[$processed_params['m_lang']] = $this->Conn->GetOne('SELECT PackName
- FROM '.TABLE_PREFIX.'Language
- WHERE LanguageId = '.$processed_params['m_lang']).'/';
+ $language_name = $this->Application->getCache('language_names', $processed_params['m_lang']);
+ if ($language_name === false) {
+ $sql = 'SELECT PackName
+ FROM '.TABLE_PREFIX.'Language
+ WHERE LanguageId = '.$processed_params['m_lang'];
+ $language_name = $this->Conn->GetOne($sql);
+ $this->Application->setCache('language_names', $processed_params['m_lang'], $language_name);
}
- $ret .= $LangCache[$processed_params['m_lang']];
+ $ret .= $language_name.'/';
}
$default_theme_id = $this->Application->GetDefaultThemeId();
if( $processed_params['m_theme'] != $default_theme_id )
{
- if (!isset($ThemesCache[$processed_params['m_theme']])) {
- $ThemesCache[$processed_params['m_theme']] = $this->Conn->GetOne('SELECT Name
- FROM '.TABLE_PREFIX.'Theme
- WHERE ThemeId = '.$processed_params['m_theme']).'/';
+ $theme_name = $this->Application->getCache('theme_names', $processed_params['m_theme']);
+ if ($theme_name === false) {
+ $sql = 'SELECT Name
+ FROM '.TABLE_PREFIX.'Theme
+ WHERE ThemeId = '.$processed_params['m_theme'];
+ $theme_name = $this->Conn->GetOne($sql);
+ $this->Application->setCache('theme_names', $processed_params['m_theme'], $theme_name);
+
}
- $ret .= $ThemesCache[$processed_params['m_theme']];
+ $ret .= $theme_name.'/';
}
- if( $processed_params['m_cat_id'] > 0 )
- {
+ if ($processed_params['m_cat_id'] > 0) {
$ret .= $this->Application->getFilename('c', $processed_params['m_cat_id']).'/';
}
@@ -100,7 +103,17 @@
$ret = preg_replace('/(.*)\//', '\\1', $ret).'_'.$processed_params['m_cat_page'].'/';
}
- $ret .= $url_params['t'].'/';
+ $template = getArrayValue($url_params, 't');
+ $category_template = $processed_params['m_cat_id'] ? $this->Application->getCache('category_templates', $processed_params['m_cat_id']) : '';
+
+ // remove template from url if it is category index cached template
+ if ($template == $category_template) {
+ $template = '';
+ }
+
+ if ($template) {
+ $ret .= $template.'/';
+ }
unset($url_params['t']);
$event->setEventParam('url_params', $url_params);
Index: trunk/core/kernel/processors/main_processor.php
===================================================================
diff -u -r4029 -r4135
--- trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 4029)
+++ trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 4135)
@@ -278,7 +278,7 @@
*/
function Get($params)
{
- $ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), EMPTY_ON_NULL);
+ $ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), '');
return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
}
Index: trunk/kernel/units/general/main_event_handler.php
===================================================================
diff -u -r4133 -r4135
--- trunk/kernel/units/general/main_event_handler.php (.../main_event_handler.php) (revision 4133)
+++ trunk/kernel/units/general/main_event_handler.php (.../main_event_handler.php) (revision 4135)
@@ -30,9 +30,6 @@
*/
function BuildEnv(&$event)
{
- static $ThemesCache = array();
- static $LangCache = array();
-
$prefix_special = $event->getPrefixSpecial();
$url_params = $event->getEventParam('url_params');
@@ -60,27 +57,33 @@
$default_language_id = $this->Application->GetDefaultLanguageId();
if( $processed_params['m_lang'] != $default_language_id )
{
- if (!isset($LangCache[$processed_params['m_lang']])) {
- $LangCache[$processed_params['m_lang']] = $this->Conn->GetOne('SELECT PackName
- FROM '.TABLE_PREFIX.'Language
- WHERE LanguageId = '.$processed_params['m_lang']).'/';
+ $language_name = $this->Application->getCache('language_names', $processed_params['m_lang']);
+ if ($language_name === false) {
+ $sql = 'SELECT PackName
+ FROM '.TABLE_PREFIX.'Language
+ WHERE LanguageId = '.$processed_params['m_lang'];
+ $language_name = $this->Conn->GetOne($sql);
+ $this->Application->setCache('language_names', $processed_params['m_lang'], $language_name);
}
- $ret .= $LangCache[$processed_params['m_lang']];
+ $ret .= $language_name.'/';
}
$default_theme_id = $this->Application->GetDefaultThemeId();
if( $processed_params['m_theme'] != $default_theme_id )
{
- if (!isset($ThemesCache[$processed_params['m_theme']])) {
- $ThemesCache[$processed_params['m_theme']] = $this->Conn->GetOne('SELECT Name
- FROM '.TABLE_PREFIX.'Theme
- WHERE ThemeId = '.$processed_params['m_theme']).'/';
+ $theme_name = $this->Application->getCache('theme_names', $processed_params['m_theme']);
+ if ($theme_name === false) {
+ $sql = 'SELECT Name
+ FROM '.TABLE_PREFIX.'Theme
+ WHERE ThemeId = '.$processed_params['m_theme'];
+ $theme_name = $this->Conn->GetOne($sql);
+ $this->Application->setCache('theme_names', $processed_params['m_theme'], $theme_name);
+
}
- $ret .= $ThemesCache[$processed_params['m_theme']];
+ $ret .= $theme_name.'/';
}
- if( $processed_params['m_cat_id'] > 0 )
- {
+ if ($processed_params['m_cat_id'] > 0) {
$ret .= $this->Application->getFilename('c', $processed_params['m_cat_id']).'/';
}
@@ -100,7 +103,17 @@
$ret = preg_replace('/(.*)\//', '\\1', $ret).'_'.$processed_params['m_cat_page'].'/';
}
- $ret .= $url_params['t'].'/';
+ $template = getArrayValue($url_params, 't');
+ $category_template = $processed_params['m_cat_id'] ? $this->Application->getCache('category_templates', $processed_params['m_cat_id']) : '';
+
+ // remove template from url if it is category index cached template
+ if ($template == $category_template) {
+ $template = '';
+ }
+
+ if ($template) {
+ $ret .= $template.'/';
+ }
unset($url_params['t']);
$event->setEventParam('url_params', $url_params);