Making the caching framework work for you (and your extensions)

TYPO3 Developer Days 2022

Frank Berger

A bit about me

  • Frank Berger
  • Head of Engineering at code711.de, a label of B-Factor GmbH, Sudhaus7 and 12bis3.de
  • Started as an Unix Systemadministrator who also develops in 1996
  • Does TYPO3 since 2005

CACHE IS GREAT!

CACHE SUCKS!

WHAT DIFFERENT CACHES IN TYPO3 DO YOU KNOW?

WHAT CAN BE CACHED?

GENERAL PATTERN

$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;
					

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

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?

LET’S CHECK THE SITE

MAKE IT UNCACHED

LET’S ADD SOME CACHING

DetailController and comments

OH NO, THE SAME PROBLEM AGAIN!

We need to clear caches if needed

WHAT MAKES A KEY?

LET’S TAKE CARE OF THE LISTS

LatestController
ListController

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.

Changes in the Backend?

I want dynamic purging

ADDING CACHE HEADERS

Ideally with a caching frontend which takes care of that

QUESTIONS AND DISCUSSIONS

Thank you, questions and resources

Twitter: @FoppelFB

https://code711.de/

fberger@code711.de

fberger@sudhaus7.de