[Phpfreechat-svn] SF.net SVN: phpfreechat: [905] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-12-20 10:31:46
|
Revision: 905 http://svn.sourceforge.net/phpfreechat/?rev=905&view=rev Author: kerphi Date: 2006-12-20 02:31:43 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Add an option to enable or disable the container memory cache + change the getContainerInstance() function to return the same container instance each time this function is called. Modified Paths: -------------- trunk/src/pfccontainer.class.php trunk/src/pfcglobalconfig.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2006-12-19 22:35:09 UTC (rev 904) +++ trunk/src/pfccontainer.class.php 2006-12-20 10:31:43 UTC (rev 905) @@ -32,11 +32,14 @@ class pfcContainer extends pfcContainerInterface { var $_container = null; // contains the concrete container instance + var $_usememorycache = true; - function pfcContainer(&$c, $type = 'File') + function pfcContainer(&$c, $type = 'File', $usememorycache = true) { pfcContainerInterface::pfcContainerInterface($c); + $this->_usememorycache = $usememorycache; + // create the concrete container instance require_once dirname(__FILE__)."/containers/".strtolower($type).".class.php"; $container_classname = "pfcContainer_".$type; @@ -493,23 +496,25 @@ { $ret = $this->_container->setMeta($group, $subgroup, $leaf, $leafvalue); - // echo "setMeta($group, $subgroup, $leaf, $leafvalue)\n"; - - if (isset($this->_cache[$group]['value']) && - !in_array($subgroup, $this->_cache[$group]['value'])) + if ($this->_usememorycache) { - $this->_cache[$group]['value'][] = $subgroup; - $this->_cache[$group]['timestamp'][] = time(); + // store the modifications in the cache + if (isset($this->_cache[$group]['value']) && + !in_array($subgroup, $this->_cache[$group]['value'])) + { + $this->_cache[$group]['value'][] = $subgroup; + $this->_cache[$group]['timestamp'][] = time(); + } + if (isset($this->_cache[$group]['childs'][$subgroup]['value']) && + !in_array($leaf, $this->_cache[$group]['childs'][$subgroup]['value'])) + { + $this->_cache[$group]['childs'][$subgroup]['value'][] = $leaf; + $this->_cache[$group]['childs'][$subgroup]['timestamp'][] = time(); + } + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = array($leafvalue); + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = array(time()); } - if (isset($this->_cache[$group]['childs'][$subgroup]['value']) && - !in_array($leaf, $this->_cache[$group]['childs'][$subgroup]['value'])) - { - $this->_cache[$group]['childs'][$subgroup]['value'][] = $leaf; - $this->_cache[$group]['childs'][$subgroup]['timestamp'][] = time(); - } - $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = array($leafvalue); - $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = array(time()); - + return $ret; } @@ -527,73 +532,73 @@ $ret = array('timestamp' => array(), 'value' => array()); - - // check in the cache - $incache = false; - if ($subgroup == null && - isset($this->_cache[$group]['value'])) + if ($this->_usememorycache) { - $incache = true; - $ret = $this->_cache[$group]; - } - else if ($leaf == null && - isset($this->_cache[$group]['childs'][$subgroup]['value'])) - { - $incache = true; - $ret = $this->_cache[$group]['childs'][$subgroup]; - } - else - { - if ($withleafvalue) + // check if the data exists in the cache + $incache = false; + if ($subgroup == null && + isset($this->_cache[$group]['value'])) { - if (isset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'])) - { - $incache = true; - $ret = $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]; - } + $incache = true; + $ret = $this->_cache[$group]; } + else if ($leaf == null && + isset($this->_cache[$group]['childs'][$subgroup]['value'])) + { + $incache = true; + $ret = $this->_cache[$group]['childs'][$subgroup]; + } else { - if (isset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'])) + if ($withleafvalue) { - $incache = true; - $ret = $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]; + if (isset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'])) + { + $incache = true; + $ret = $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]; + } } + else + { + if (isset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'])) + { + $incache = true; + $ret = $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]; + } + } } + if ($incache) + { + $ret = array('timestamp' => $ret['timestamp'], + 'value' => $ret['value']); + return $ret; + } } - - // echo "getMeta($group, $subgroup, $leaf, $withleafvalue)".($incache?"incache":"notincache")."\n"; - - if ($incache) - { - $ret = array('timestamp' => $ret['timestamp'], - 'value' => $ret['value']); - return $ret; - } - // get the fresh data $ret = $this->_container->getMeta($group, $subgroup, $leaf, $withleafvalue); - - // store in the cache - if ($subgroup == null) + if ($this->_usememorycache) { - $this->_cache[$group]['value'] = $ret['value']; - $this->_cache[$group]['timestamp'] = $ret['timestamp']; - } - else if ($leaf == null) - { - $this->_cache[$group]['childs'][$subgroup]['value'] = $ret['value']; - $this->_cache[$group]['childs'][$subgroup]['timestamp'] = $ret['timestamp']; - } - else - { - if ($withleafvalue) - $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = $ret['value']; + // store in the cache + if ($subgroup == null) + { + $this->_cache[$group]['value'] = $ret['value']; + $this->_cache[$group]['timestamp'] = $ret['timestamp']; + } + else if ($leaf == null) + { + $this->_cache[$group]['childs'][$subgroup]['value'] = $ret['value']; + $this->_cache[$group]['childs'][$subgroup]['timestamp'] = $ret['timestamp']; + } else - unset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value']); - $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = $ret['timestamp']; + { + if ($withleafvalue) + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = $ret['value']; + else + unset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value']); + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = $ret['timestamp']; + } } return $ret; @@ -609,45 +614,40 @@ */ function rmMeta($group, $subgroup = null, $leaf = null) { - //echo "rmMeta($group, $subgroup, $leaf)\n"; - - // if ($group == "channelid-to-nickid") - // { echo "avant\n"; print_r($this->_cache[$group]); } - - // remove from the cache - if ($group == null) - $this->_cache = array(); - else if ($subgroup == null) - unset($this->_cache[$group]); - else if ($leaf == null) + if ($this->_usememorycache) { - if (isset($this->_cache[$group]['value'])) + // remove from the cache + if ($group == null) + $this->_cache = array(); + else if ($subgroup == null) + unset($this->_cache[$group]); + else if ($leaf == null) { - $i = array_search($subgroup,$this->_cache[$group]['value']); - if ($i !== FALSE) + if (isset($this->_cache[$group]['value'])) { - unset($this->_cache[$group]['value'][$i]); - unset($this->_cache[$group]['timestamp'][$i]); + $i = array_search($subgroup,$this->_cache[$group]['value']); + if ($i !== FALSE) + { + unset($this->_cache[$group]['value'][$i]); + unset($this->_cache[$group]['timestamp'][$i]); + } } + unset($this->_cache[$group]['childs'][$subgroup]); } - unset($this->_cache[$group]['childs'][$subgroup]); - } - else - { - if (isset($this->_cache[$group]['childs'][$subgroup]['value'])) + else { - $i = array_search($leaf,$this->_cache[$group]['childs'][$subgroup]['value']); - if ($i !== FALSE) + if (isset($this->_cache[$group]['childs'][$subgroup]['value'])) { - unset($this->_cache[$group]['childs'][$subgroup]['value'][$i]); - unset($this->_cache[$group]['childs'][$subgroup]['timestamp'][$i]); + $i = array_search($leaf,$this->_cache[$group]['childs'][$subgroup]['value']); + if ($i !== FALSE) + { + unset($this->_cache[$group]['childs'][$subgroup]['value'][$i]); + unset($this->_cache[$group]['childs'][$subgroup]['timestamp'][$i]); + } } + unset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]); } - unset($this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]); } - - // if ($group == "channelid-to-nickid") - // { echo "apres\n"; print_r($this->_cache[$group]); } return $this->_container->rmMeta($group, $subgroup, $leaf); } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-12-19 22:35:09 UTC (rev 904) +++ trunk/src/pfcglobalconfig.class.php 2006-12-20 10:31:43 UTC (rev 905) @@ -235,19 +235,22 @@ */ function &getContainerInstance() { - // bug in php4: cant make a static pfcContainer instance because // it make problems with pfcGlobalConfig references (not updated) // it works well in php5, maybe there is a workeround but I don't have time to debug this // to reproduce the bug: uncomment the next lines and try to change your nickname // the old nickname will not be removed - // static $container; - // if (!isset($container)) - // { - require_once dirname(__FILE__).'/pfccontainer.class.php'; - $container =& new pfcContainer($this,$this->container_type); + // @todo : check if this bug is already present in php4 + static $container; + if (!isset($container)) + { + require_once dirname(__FILE__).'/pfccontainer.class.php'; + $container =& new pfcContainer($this, // the config instance + $this->container_type, // the container type + true // usememorycache + ); + } return $container; - // } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |