Typo3 Workshop @ T3DD19 - Make the cache work for you

Typo3 Workshop @ T3DD19 - Make the cache work for you

A step by step primer to add your own caching logic to your extbase extension.
Code is available on Gihub: https://github.com/foppelfb/workshop/
the Steps are available as Branches https://github.com/foppelfb/workshop/branches

E789161a9b29490b909728b6e4811871?s=128

Frank Berger

August 03, 2019
Tweet

Transcript

  1. WORKSHOP Making the caching framework 
 work for you (and

    your extensions)
  2. • Frank Berger (Greybeard) • Head of Engineering
 B-FACTOR Sudhaus7

    • started 1996 as Unix Systemadministrator who also programs (aka „Devops“) Sudhaus7 A SHORT NOTE ABOUT ME
  3. Sudhaus7 CACHE IS GREAT!

  4. Sudhaus7 CACHE SUCKS!

  5. WHAT DIFFERENT CACHES IN TYPO3 DO YOU KNOW? Sudhaus7

  6. WHAT CAN BE CACHED? Sudhaus7

  7. $cache = new CacheManager(); // Generate key $key = ‘something-unique-to-identify-this-peace-of-content’;

    // fetch data if (($data = $cache->get($key) === false) { // do what needs to be cached $data = timeAndResourceExpensiveOperation(); // define tags $tags[‘tag_1’,’pageId_x’]; // store data (forever) $cache->set($key,$data,$tags,0) } // use data return $data; Sudhaus7 GENERAL PATTERN
  8. Sudhaus7 SOME TERMINOLOGY • cacheKey - a unique identifier which

    considers all necessary 
 context that defines the current state and result • tags - related information on which this cache should be purged • cacheFrontend - the mechanism which handles the data • cacheBackend - the mechanism which stores the data
  9. WHAT MAKES A KEY? Sudhaus7

  10. WHAT MAKES A KEY? • Datatype - What is it?

    • Plugin - Where does it run in? • Source - where is it read from? • Target - in what context is it displayed? • Page • Column • Language • Actor - who is using the website? Sudhaus7
  11. SETTING UP THE WORKSHOP ENVIRONMENT • git clone https://github.com/foppelfb/workshop.git
 or

    download zip from here:
 https://github.com/foppelfb/workshop/archive/master.zip • cd workshop • ddev start • ddev composer install • http://workshop.ddev.site:8080/ • User: admin Password: password Sudhaus7
  12. Sudhaus7 AVAILABLE EXTRA COMMANDS • ddev composer killcache
 (will flush

    the cache) • ddev composer t3update
 (will call install:extensionsetupifpossible)
  13. Sudhaus7 LET’S CHECK THE SITE

  14. Sudhaus7 MAKE IT UNCACHED

  15. DetailController
 and comments Sudhaus7 LET’S ADD SOME CACHING

  16. Sudhaus7 OH NO, THE SAME PROBLEM AGAIN! We need to

    clear caches if needed
  17. Sudhaus7 LET’S TAKE CARE OF THE LISTS LatestController ListController

  18. Sudhaus7 GOOD TO KNOW • tag [pageId_$pid] will be purged

    when the cache-clear 
 for the page with this pid is called • an Extbase Controller Action can return the content. If it does 
 not return the content, $this->view->render() will be called.
  19. Sudhaus7 CHANGES IN THE BACKEND? I want dynamic purging

  20. Sudhaus7 ADDING CACHE HEADERS Ideally with a caching frontend which

    takes care of that
  21. Sudhaus7 QUESTIONS AND DISCUSSIONS

  22. Frank Berger Sudhaus7 (eine Marke der B-FACTOR GmbH) fberger@sudhaus7.de Twitter:

    @foppelfb https://github.com/foppelfb Sudhaus7 THANK YOU!