1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Caching for Add-ons

Discussion in 'Development Tutorials [Archive]' started by ragtek, Oct 28, 2010.

  1. ragtek

    ragtek Guest

    Because XenForo uses Zend Cache, you can use the nice Caching feature also for your admins.


    The coders, who uses vB4 and know how nice the cache is, don't need to miss it in XenForo.

    I love the cache, because it uses a timeout AND you can have Tags/Events on which tyou can delte the Cache Entries.

    For examle:
    If you want to show the 10 newest users/threads/posts/whatever on your indexpage, you have huge queries, which run on every index view.

    So what can we do, to save the queries?
    We can cache the result.
    Now if you use the cache you would use:
    PHP:
     $cache XenForo_Application::get('cache');
    $data = array('foo','bar''tap'); // my results;)
                
    $cache->save($data,
                            
    'myId');
    which would cache the elements for the general lifetime you set up in your config.php

    BUT why renew the cache element, if the cache content didn't change?
    For this, you can use the Cache Tags (for former vB Add-on Coders => cache events ;) )


    PHP:
    $data = array('foo','bar''tap');
                
    $cache->save($data,
                            
    'meineragtekid',
                            array(
    'newthread_created''thread_deleted')
                        );
    Now we saved the newest threads, and defined 2 tags for this => 'newthread_created' & 'thread_deleted'
    That's important, because i want the box "up2date" so i have to "empty the cacheelements" when somebody creates,edits or deletes a thread.

    To make this, we have now to empty the defined tags after creating a thread.

    1. $cache->clean(
    2. Zend_Cache::CLEANING_MODE_MATCHING_TAG,
    3. array('newthread_created')
    4. );


    That's a "article" about caching, so i don't want to explain here, how to expant the thread datawriter to make this;)


    This is just a quick example, but i hope you enjoy and use it;)
    (Sorry for my bad english, i hope you understand it^^ )
     
    SheepCow, DeltaHF, DarkSign and 2 others like this.
  2. Fuhrmann

    Fuhrmann Well-Known Member

    Would be nice to have this article extended.
     

Share This Page