Page 1 of 1

IMPROVEMENT REQUEST - JCache and whole of joomla?

Posted: Sun Nov 15, 2009 1:23 pm
by e-motiv
I saw the following code in 1.5 and 1.6 (trunk) for the JCache object and I thought it could be improved. Old code:

Code: Select all

function __construct($options)
    {
        $this->_options = &$options;

        // Get the default group and caching
        if (isset($options['language'])) {
            $this->_options['language'] = $options['language'];
        } else {
            $options['language'] = 'en-GB';
        }

        if (isset($options['cachebase'])) {
            $this->_options['cachebase'] = $options['cachebase'];
        } else {
            $this->_options['cachebase'] = JPATH_ROOT.DS.'cache';
        }

        if (isset($options['defaultgroup'])) {
            $this->_options['defaultgroup'] = $options['defaultgroup'];
        } else {
            $this->_options['defaultgroup'] = 'default';
        }

        if (isset($options['caching'])) {
            $this->_options['caching'] =  $options['caching'];
        } else {
            $this->_options['caching'] = true;
        }

        if (isset($options['storage'])) {
            $this->_options['storage'] = $options['storage'];
        } else {
            $this->_options['storage'] = 'file';
        }

        //Fix to detect if template positions are enabled...
        if (JRequest::getCMD('tpl',0)) {
            $this->_options['caching'] = false;
        }
    }
 
New code:

Code: Select all

function __construct($options)
    {
        $this->_options = array(
            'language'=>'en-GB',
            'cachebase'=>JPATH_ROOT.DS.'cache',
            'defaultgroup'=>'default',
            'caching'=>true,
            'storage'=>'file');

        //Overwrite default options with given options
        $this->_options = array_merge($this->_options,$options); 
//or with the ampersand "...& $options);" for speed if array_merge or this construct would make a deep copy otherwise

        //Fix to detect if template positions are enabled...
        if (JRequest::getCMD('tpl',0)) {
            $this->_options['caching'] = false;
        }
    } 
Why?
  1. It generates far less php code.
  2. It is much faster.
  3. It allows quick and easy addition of future parameteres to developers
Further possible improvements
I also propose...
  1. ..to use this technique wherever this kind of constructor occurs in the joomla library (with array that sets options or similar).
  2. ..to make a function in JObject (e.g. setOptions(..)) to handle this (for even more improvement)
  3. ..to alter a lot of other joomla library objects to be written as thus (in stead of the old method e.g. function something(opt1, opt2, opt3))(and even more :eek:)
This way, this technique would not only improve one object (JCache) with small improvements, but an immense lot of possible objects with a relatively noticeable improvement in the whole of Joomla.

What do you thinks guys?

Re: IMPROVEMENT REQUEST - JCache and whole of joomla?

Posted: Sun Nov 15, 2009 4:02 pm
by Hackwar
Hi e-builds,
this sounds good. Can you post this to the Joomla development CMS mailinglist? This would not be something that we would add to 1.5, but if you would provide a patch for 1.6, we could take a serious look at implementing this.

Hannes

Re: IMPROVEMENT REQUEST - JCache and whole of joomla?

Posted: Mon Nov 16, 2009 11:05 pm
by e-motiv
Patch submitted:http://groups.google.com/group/joomla-d ... 0404361045

More opinions and thoughts needed about "Further possible improvements" above.

Re: IMPROVEMENT REQUEST - JCache and whole of joomla?

Posted: Mon Dec 21, 2009 11:32 am
by e-motiv
Why is no-one answering to that post on the mailinglist?
Is this normal (wait time) or did I do something the wrong way?

Re: IMPROVEMENT REQUEST - JCache and whole of joomla?

Posted: Thu Dec 31, 2009 9:05 am
by darb
Well hope you get some attention really for this Joomla improvement even it have been Christmas and holidays.

It will be interesting to see how it work now with a better integration of new submitted improvements from the community.

Feedback anyone ?


So who evaluate, decide and take care of this patch?

Happy New Joomla Year!