Cacheability metadata
Cacheability metadata is used to describe the thing that is rendered with respect to its dynamism. Most of the time, as Drupal module developers, we will be using this metadata when working with render arrays. We will see a bit later where else these come into play, but for now, let’s see what the actual properties are and what they are used for in the context of render arrays.
When creating render arrays, there are a few things we need to think about when it comes to caching. And we always need to think about these things.
Cache tags
The first thing we need to think about is what our render array depends on. Are we rendering some entity data? Are we using some configuration values? Is anything that might be changed elsewhere, impacting what we have to render? If the answer is yes, we need to use cache tags. If we don’t use them, our render array gets cached as it is, and if the underlying data changes, we end up showing our users stale...