wimleers.com
@wimleers
Senior Software Engineer
Office of the CTO, Acquia
Drupal 8 ⟹ you cannot apply this today!
“There are only two hard problems in Computer Science: cache invalidation and naming things.”
⬇
poor performance
⬇
more servers
… clears the entire page cache on node save!
cache_clear_all('foo:content:id', $bin);
cache_clear_all('foo:content:', $bin, TRUE);
cache_clear_all('*', $bin, TRUE);
⬇
“How to clear all entries containing node 42?”
⬇
Impossible!
cache($bin)->set($cid, $value, CACHE_PERMANENT, $tags);
$tags = array('content' => TRUE);
$tags = array(
'node' => array(42)
);
$tags = array(
'node' => array(42),
'user' => array(314),
'taxonomy_term' => array(1337, 9001),
);
$element['#cache'] = array(
'keys' => array('entity_view', $entity_type, $entity_id, $view_mode),
'granularity' => DRUPAL_CACHE_PER_ROLE,
'tags' => array(
$entity_type . '_view' => TRUE,
$entity_type => array($entity_id),
),
);
+
/**
* Collects cache tags for an element and its children into 1 array.
*
* […] This allows items to be invalidated based on all tags attached
* to the content they're constituted from.
*/
function drupal_render_collect_cache_tags($element) { … }
Clear caches:
deleteTags()
: prevents stale contentinvalidateTags()
: allows stale content
⟹ breaks render cache
or
⟹ compatible with render cache
Contextual IDs in HTML
+
contextual.js
(If Use contextual links permission.)
+
POST contextual IDs to contextual/render
=
Same HTML for all users!
(Personalization applied later)
Use cache tags precisely (cache invalidation)
Personalize via JS, cache client-side (cache filling)
data-
attributeslocalStorage
⬇
Painful mess.
“API”:
#aggregate_callback
#group_callback
⬇
Override the whole, or nothing … or hacks
⬇
Incompatibility hell: Omega theme, CDN module …
API:
Identical logic, but restructured
(See d.o/node/2034675)
AssetCollectionOptimizerInterface
AssetCollectionGrouperInterface
AssetOptimizerInterface
AssetDumperInterface
AssetCollectionRendererInterface
Override at will!
asset.css.collection_renderer:
class: Drupal\Core\Asset\CssCollectionRenderer
asset.css.collection_optimizer:
class: Drupal\Core\Asset\CssCollectionOptimizer
arguments: [ '@asset.css.collection_grouper', '@asset.css.optimizer', '@asset.css.dumper', '@state' ]
asset.css.optimizer:
class: Drupal\Core\Asset\CssOptimizer
asset.css.collection_grouper:
class: Drupal\Core\Asset\CssCollectionGrouper
asset.css.dumper:
class: Drupal\Core\Asset\AssetDumper
asset.js.collection_renderer:
…
asset.js.collection_optimizer:
…
asset.js.optimizer:
…
asset.js.collection_grouper:
…
asset.js.dumper:
…
mtime
Override individual asset services
wimleers.com/talk/drupal-8-perf-ops
More details & depth:
wimleers.com/talk/really-fast-drupal-8