Joomla 1.6. caching implemented #jab11


Published on

Slides from Joomla 1.6. Caching workshop at Jandbeyond conference 2011

Published in: Technology
1 Like
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Joomla 1.6. caching implemented #jab11

  1. 1. JOOMLA! 1.6. CACHE //implemented //
  3. 3. // Cache types coverage //templatecomponentmodulesmodulefunctions limited to component limited to modules limited to modulesmallerunits page cache component progressive module function/callback output cache view cache cache cache cache raw cache
  4. 4. page cache// Cache types coverage //
  5. 5. component view cache// Cache types coverage //
  6. 6. progressive cache// Cache types coverage //
  7. 7. module cachee.g. mod_latestnews// Cache types coverage //
  8. 8. function cacheoutput Caching smaller units insideraw cache framework and extensions (not directly visible)// Cache types coverage //
  9. 9. multiple caches =multiple layers// Cache types coverage //
  10. 10. multiple caches =multiple layers// Cache types coverage //
  11. 11. PAGE CACHE
  12. 12. Takes snapshots of entire pages including everything -component, modules, plugins and a template.The widest and the least flexible approach of all cachingoptions.// enabled by core system plugin -> site administrators choice //
  14. 14. Takes snapshot of each unique modules set (typicaly eachpage)Affects all modules - works as layer above module cache.// enabled by setting cache level to progressive -> site administrators choice. For finegrained control over each module cache use conservative caching level. //
  16. 16. Most widespread cache type, sometimes equaled with Jcaching in general. Performs well in the speed terms Disables any user<->extension<->framework interaction until a cached copy has expiredNot suitable for any components or modules that react touser actions or render frequently changing content.
  17. 17. COMPONENT VIEW CACHETakes an array of url parameters and their types to createCacheid.A replacement for a previous unsafe way which took thewhole URL and so opened the doors for DOS attacks viarandom parameters/values added to request// Old cacheid created from URL retained for backwards compatibility if there are no$safeurlparams (to be removed in 1.7) //
  18. 18. Com_contact controler usage example:$safeurlparams = array(id=>INT, catid=>INT, limit=>INT,limitstart=>INT, filter_order=>CMD, filter_order_Dir=>CMD’,lang=>CMD);parent::display($cachable,$safeurlparams);
  19. 19. MODULE CACHE5 different modes of operation, 3 of them are to be setfrom module XML file, while 2 are meant to be used fromwithin the module itself.Default is backwards compatible oldstatic mode thatrequires no changes to a module.
  20. 20. MODES TO BE SET IN XMLStatic - one cache file for all pages with the same moduleparameters.Recommended for modules that dont change.Oldstatic - 1.5. definition of module caching, one cachefile for all pages with the same module id and user aid.Default for backwards compatibility
  21. 21. MODES TO BE SET IN XMLItemid - changes on itemid change.Suitable for most dynamic modules that change per page- like menus, breadcrumbs, content images etc
  22. 22. In addition to cache field that was required in 1.5 there isnow new hidden field in module XML called cachemodethat sets any of the above modes.<field name="cachemode"type="hidden"default="static"><option value="static"></option></field>
  23. 23. MODES TO BE CALLED FROM INSIDE THE MODULE:Safeuri - id is created from URL params array, as incomponent view cacheUse this mode if you module depends on url parametersother than Itemid to display content (e.g. module thatdisplay different image for each content category).Modeparams property is an array of url parameters andtheir filter types
  24. 24. MODES TO BE CALLED FROM INSIDE THE MODULE:Id - module sets own cache ids according to its ownformula.Most flexible, but not needed often.Modeparams property is calculated id.
  25. 25. To use this modes rename cache field in xml toowncache field and call JModuleHelper::ModuleCache from withinthe modules main php file.// actually a shortcut to cache callback to avoid code duplication in every module //
  26. 26. An example that uses safeuri mode$list = modRelatedItemsHelper::getList($params) :$cacheparams->modeparams = array(id=>int,Itemid=>int);$cacheparams->methodparams = $params;$cacheparams->method = getList;$cacheparams->class = modRelatedItemsHelper;$cacheparams->cachemode = safeuri;$cacheparams = new stdClass;$list = JModuleHelper::ModuleCache ($module, $params, $cacheparams);
  28. 28. The first of flexible caching types that enable us todifferentiate between various parts of the extension andcache only those parts that are cacheable, while keepingdynamic parts uncached.
  29. 29. Caches results of function callsRecords (cacheID) based on the arguments passed to thefunction
  30. 30. Often useful to cache model methods and keep viewsuncached.Example useModel performing expensive queries or similar operationsis run only once to create a larger pool of data which isthen further manipulated inside the view (sorting,pagination, calculations etc.)
  31. 31. OUTPUT CACHE
  32. 32. Caches output of some part od the scriptRecords based on id passed
  33. 33. Basically output buffering with caching
  34. 34. RAW CACHE
  35. 35. Caches any data unitsRecords based on id passed
  36. 36. Fully controlled by the coder – what, when to store, howto classify stored units (cache id).Highly useful when we are dealing with finite number ofreusable data units
  37. 37. Example useHigh number of possible combinations of relatively smallnumber of units – e.g. products in online store. No pointto cache multiple parameter searches, cache each productseparately.Other examplesExpensive queries, remote XML, thumbnails, reusabletexts or any reusable data set.
  38. 38. Also useful to pass large amounts of data betweendifferent parts of application (e.g. steps in click flow)Used in Joomla core: list of components, list of modules,menu tree, available languages, user groups, htmlrenderers etc.
  39. 39. Raw cache get and store are easily accesed by passing (empty string) as cache controller to JFactory::getCacheData is auto serialized / deserializedLocking & unlocking are performed automaticaly