Change record status: 
Introduced in branch: 
3.4.x
Introduced in version: 
3.4.0
Description: 

The addCacheableDependencies method in the HostEntity class has been deprecated because it adds cache contexts and tags that may not be appropriate for all use cases. For example, the user.permissions context is added for any logged in user, even if the render array being built by the caller is not sensitive to permissions.

No replacement is offered. Instead, developers should add the appropriate cacheability metadata on a case by case basis. The host entity now implements the RefinableCacheableDependencyInterface, so it is easy to add a cache dependency on the host entity when needed. The host entity manages its own dependencies per #3497735: HostEntity should implement CacheableDependencyInterface, so developers no longer need to know the internals of the HostEntity class to determine the dependencies that need to be added.

Before

$settings = $host_entity->getSettings();
$registration_type = $host_entity->getRegistrationType();
$host_entity->addCacheableDependencies($render_array, [$settings, $registration_type]);

After

$metadata = CacheableMetadata::createFromRenderArray($render_array);
$metadata->addCacheableDependency($host_entity)->applyTo($render_array);

If the render array should be built differently for users with different permissions:

$metadata = CacheableMetadata::createFromRenderArray($render_array);
$metadata->addCacheContexts(['user.permissions']);
$metadata->addCacheableDependency($host_entity)->applyTo($render_array);

If the render array should rebuild when registrations for the host entity are added, updated or deleted:

$metadata = CacheableMetadata::createFromRenderArray($render_array);
$metadata->addCacheTags([$host_entity->getRegistrationListCacheTag()]);
$metadata->addCacheableDependency($host_entity)->applyTo($render_array);
Impacts: 
Module developers