Drupal - Using cache tags for a particular node list
In this case I know two options.
One - Include all node tags (node:{#id}), if doesn't matter if a new node of a particular type was added.
Two - Create and control your own cache tag, and invalidade it when you want.
I'm developing a site that was needed create a term list cache per vocab_id. In this case every time that a term from a particular vocab_id change/add/delete the cache tag is invalided using Cache::invalidateTags($tag_id)
then my block will be rebuild.
Edit 1
Example:
use Drupal\Core\Cache\Cache;
function filters_invalidate_vocabulary_cache_tag($vocab_id) {
Cache::invalidateTags(array('filters_vocabulary:' . $vocab_id));
}
In your case maybe is just change $vocab_id
for $node_type
.
Starting Drupal 8.9.0, there is a new ENTITY_TYPE_list:BUNDLE
cache tag added (see the change record).
So in your case you would simply need to tag our list with node_list:book
.
https://www.drupal.org/node/3107058