[TUTORIAL] Using Caching to Speed Up Your Code

Submit your own tutorials, guides and API documents for inclussion in the Official Developer Documentation.
Locked
User avatar
mjaz
Joomla! Guru
Joomla! Guru
Posts: 821
Joined: Thu Nov 10, 2005 10:08 am
Contact:

[TUTORIAL] Using Caching to Speed Up Your Code

Post by mjaz » Fri Jan 05, 2007 8:55 pm

Hi,

I wrote a very basic quickstart tutorial on caching functions in 1.5. Feel free to edit it, rewrite it, publish it in the wiki, tattoo it on your forehead, or ignore it :)


EDIT: removed attachment. Read it at http://dev.joomla.org/component/option, ... g_caching/
Last edited by mjaz on Mon Jan 08, 2007 6:52 pm, edited 1 time in total.
Better SEO & multi-lingual Joomla sites with Nooku Content
http://www.nooku.org
Nooku Framework for advanced Joomla extension development
http://www.nooku.org/framework

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Fri Jan 05, 2007 10:19 pm

Hi mjaz,

Excellent work Mathias.  This is just the kind of material we need right now.  I'll get it edited, formatted and posted on the dev wiki shortly.

In the meantime a big thank you and please feel free to write some more.  :D

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
Jinx
Joomla! Champion
Joomla! Champion
Posts: 6508
Joined: Fri Aug 12, 2005 12:47 am
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Jinx » Fri Jan 05, 2007 11:55 pm

Keep in mind that the whole caching layer is still in WIP and is slated to undergo a refactoring (it's the last major part of the architecture we still need to deal with). We hope to start on it soonish, probably end of next week.

Good work nevertheless, especialy the profiler stuff is fixed and will not change so this can be documented already.
Last edited by Jinx on Fri Jan 05, 2007 11:57 pm, edited 1 time in total.
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.joomlatools.com - Joomla extensions that just work

User avatar
mjaz
Joomla! Guru
Joomla! Guru
Posts: 821
Joined: Thu Nov 10, 2005 10:08 am
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by mjaz » Sat Jan 06, 2007 12:48 am

I needed caching for an extension i'm making. I couldn't find any docs, so I decided to document my progress as I discovered how it works. Didn't know it was still WIP. If the api changes, let us know.

btw Respect to the doc people  :-* , I never imagined writing even such a basic tut could be such hard work. I'll see if I can write some more, no promises though.
Better SEO & multi-lingual Joomla sites with Nooku Content
http://www.nooku.org
Nooku Framework for advanced Joomla extension development
http://www.nooku.org/framework

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Sat Jan 06, 2007 2:32 pm

mjaz wrote: I never imagined writing even such a basic tut could be such hard work.
"What's easy reading is damned hard writing."  G. K. Chesterton (if memory serves)  :)

@Johan.  Thanks for the warning, I'd forgotten about that.  I'll post it on the dev wiki anyway, but I'll include a prominent health warning too.

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Sat Jan 06, 2007 4:01 pm

Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
Jinx
Joomla! Champion
Joomla! Champion
Posts: 6508
Joined: Fri Aug 12, 2005 12:47 am
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Jinx » Sat Jan 06, 2007 5:10 pm

Thanks guys ! Good team work I call this one.
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.joomlatools.com - Joomla extensions that just work

User avatar
mjaz
Joomla! Guru
Joomla! Guru
Posts: 821
Joined: Thu Nov 10, 2005 10:08 am
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by mjaz » Thu Feb 01, 2007 9:41 pm

After a quick look at the changes in svn, this should be changed in the tutorial:

1. The profiler apparently is not available by default, so all code should have:

Code: Select all

jimport( 'joomla.utilities.profiler' );
2. cleanCache() is now clean():

Code: Select all

$cache->clean();
instead of

Code: Select all

$cache->cleanCache();
3. When getting a reference to the cache object, it will default to 'output', but we need 'callback', so:

Code: Select all

// Get a reference to the global cache object.
$cache = & JFactory::getCache( 'callback' );
4. call() is a wrapper for get(), so we'll use:

Code: Select all

$rows  = $cache->get( array( 'TestClass', 'testMethod' ), $table );

The complete code in part 5 of the tut now looks like this:

Code: Select all

<?php
jimport( 'joomla.utilities.profiler' );

class TestClass {

    function testMethod( $table ) {

        // Get a reference to the global database object.
        $db = & JFactory::getDBO();

        // Execute the same database query 250 times.
        for( $i=0; $i<250; $i++) {
            $db->setQuery( "SELECT * FROM #__$table" );
            $rows = $db->loadObjectList();
        }

        return $rows;
    }
}

// Determine which database table to query.
$table = JRequest::getVar( 'table', 'content' );

// Get a reference to the global cache object.
$cache = & JFactory::getCache('callback' );

// Run the test without caching.
$profiler = new JProfiler();
$rows = TestClass::testMethod( $table );
echo $profiler->mark( ' without caching' );

// Run the test with caching.
$profiler = new JProfiler();
$rows  = $cache->get( array( 'TestClass', 'testMethod' ), $table );
echo $profiler->mark( ' with caching' );
?>
The other code examples should be changed as well.

I'll keep an eye out for any further changes to the svn.
Better SEO & multi-lingual Joomla sites with Nooku Content
http://www.nooku.org
Nooku Framework for advanced Joomla extension development
http://www.nooku.org/framework

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Thu Feb 01, 2007 10:46 pm

Hi mjaz,

Rather than update the wiki right now I think I'll wait until we can be certain that the refactoring of the cache code has been completed.  Last I heard it was still work in progress.

Thanks for the update Mathias.

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
Jinx
Joomla! Champion
Joomla! Champion
Posts: 6508
Joined: Fri Aug 12, 2005 12:47 am
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Jinx » Thu Feb 01, 2007 11:25 pm

It still is indeed, while the code is roughly done we still need to implement it and this usualy goes with some refactoring.
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.joomlatools.com - Joomla extensions that just work

User avatar
mjaz
Joomla! Guru
Joomla! Guru
Posts: 821
Joined: Thu Nov 10, 2005 10:08 am
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by mjaz » Thu Feb 01, 2007 11:30 pm

Ok. Maybe you can add backlink to this thread in the wiki.
Better SEO & multi-lingual Joomla sites with Nooku Content
http://www.nooku.org
Nooku Framework for advanced Joomla extension development
http://www.nooku.org/framework

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Fri Feb 02, 2007 12:25 am

Good idea.  Done.

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
markuz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 225
Joined: Tue Nov 08, 2005 6:43 pm
Location: the Netherlands
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by markuz » Fri Jun 01, 2007 9:25 am

Jinx wrote: It still is indeed, while the code is roughly done we still need to implement it and this usualy goes with some refactoring.
Jinx,

What is the status of the code regarding to caching? I'm exploring the possibilities for my component.

I'm facing several issues like: pathway building problems, registration of 'hits', JToolbarHelper doesn't get called in the backend, etc. etc. Are these issues to be solved, or is it simply not covered by the cache layer?

Thanks in advance,
Mark
Last edited by markuz on Fri Jun 22, 2007 11:06 am, edited 1 time in total.

Joombla
Joomla! Intern
Joomla! Intern
Posts: 71
Joined: Mon Sep 12, 2005 7:54 am

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Joombla » Wed Jun 06, 2007 10:27 pm

I'm with Markuz, before I go digging around too much with this, does the article stand correct, or is the cache completely refactored and invalidates this article?

Todd

User avatar
torkil
Joomla! Guru
Joomla! Guru
Posts: 726
Joined: Wed Aug 24, 2005 9:34 am
Location: Rørvik, Norway
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by torkil » Fri Jun 22, 2007 9:34 am

Same question. :)

User avatar
torkil
Joomla! Guru
Joomla! Guru
Posts: 726
Joined: Wed Aug 24, 2005 9:34 am
Location: Rørvik, Norway
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by torkil » Fri Jul 06, 2007 11:45 am

I forgot to say that I got a response to this: The cache code is done. :)

User avatar
markuz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 225
Joined: Tue Nov 08, 2005 6:43 pm
Location: the Netherlands
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by markuz » Fri Jul 06, 2007 2:40 pm

Thanks Torkil,

Still have the following issues though...
markuz wrote: I'm facing several issues like: pathway building problems, registration of 'hits', JToolbarHelper doesn't get called in the backend, etc. etc. Are these issues to be solved, or is it simply not covered by the cache layer?
Mark

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by AmyStephen » Sun Aug 12, 2007 4:48 am

The wiki points to this thread - and this thread points to the wiki - as the most current documentation. Following is from the wiki.
Warning: The Joomla! 1.5 cache API is currently being refactored and you should not rely on the information contained in this tutorial remaining true. Further information may be found in this forum thread.
It appears the wiki is up to date, now. Should the wiki warning now be removed?

Thanks!
Amy :)

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Thu Aug 16, 2007 12:17 pm

Wiki warning has been removed.

Thanks for the reminder Amy.

Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
Kampp
Joomla! Guru
Joomla! Guru
Posts: 564
Joined: Tue Aug 30, 2005 9:18 am
Location: Denmark
Contact:

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Kampp » Sun Jun 14, 2009 3:51 pm

The wiki link does not work anymore.... :(
https://toolmaster.dk - Danish Joomla Services
https://joomla-hosting.dk - Danish Joomla hosting
https://joomla-konsulent.dk - Danish Joomla Services

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: [TUTORIAL] Using Caching to Speed Up Your Code

Post by Chris Davenport » Sun Jun 14, 2009 6:08 pm

It's been moved to the "new" wiki: http://docs.joomla.org/Using_caching_to ... _your_code

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/


Locked

Return to “Submit”