I have a block, created with a custom block plugin (extending BlockBase), that shows on every page, and I want to cache its data, to speed up performance.
I have added cache tags to the build() function:
$build['#cache']['tags'] = $cache_tags;
But the build() function is still executing on each page load. I guess because the cache tags are for render cache, not data cache.
Is there a built in way to cache the data in the build() function for a block for logged in users?
Or do I have to add custom caching in the build function, like this:
if ($cache = \Drupal::cache()->get($cid)) {
https://api.drupal.org/api/drupal/core!core.api.php/group/cache/8.2.x