Clear entity cache before render I secured some file in an s3 bucket using s3fs.
My problem is : the &quot;Expires&quot; argument send to build the file URI is not reset each time the object is call in my API.
time doesn't change if I don't clear the cache with drush
$expires = time() + 10;

So I tried to use hook_entity_view :
if ($entity-&gt;bundle() === 'my_bundle') {
    foreach ($entity-&gt;getCacheTags() as $tag) {
      $tags[] = $tag;
    }
  }

Doesn't work
Drupal::entityTypeManager()-&gt;getStorage($entityType)-&gt;resetCache();

Nop
\Drupal::service('cache.render')-&gt;deleteAll();
\Drupal::service('cache.entity')-&gt;deleteAll();
\Drupal::service('cache.data')-&gt;deleteAll();

deleteAll or invalidateAll, none of it work.
drupal_flush_all_caches();

Nothing, I'm starting to think I have config problem...
If someone can save me !
UPDATE
It seems hook_entity_load works with my API, it clear the cache correctly.
The problem remains when i'm trying to watch the content in my Drupal website, in the content view.
Ok everything is fixed, there were 2 points :

Clean the cache when the media 'masterclass_private_video' is called, so the request to AWS s3 has the correct &quot;Expires&quot; timestamp when call by my VueJs API.
Clean the render cache of the content view in my drupal backend.

Clean the media cache for the API :
function mymodule_entity_load(array $entities, $entity_type_id)
{
  $tags = [];
  foreach ($entities as $entity) {
    if ($entity-&gt;bundle() === 'masterclass_private_video') {
      foreach ($entity-&gt;getCacheTags() as $tag) {
        $tags[] = $tag;
      }
    }
  }

  if (!empty($tags)) {
    Cache::invalidateTags($tags);
  }
}

Clean the page cache :
function mymodule_node_view_alter(array &amp;$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display)
{
  if ($entity-&gt;bundle() === 'masterclass' || $entity-&gt;bundle() === 'masterclass_chapter') {
    $build['#cache']['max-age'] = 0;
    \Drupal::service('page_cache_kill_switch')-&gt;trigger();
  }
}

To be clear, the goal is to reset the $expires, so the AWS s3 works :
function mymodule_s3fs_url_settings_alter(array &amp;$url_settings, $s3_file_path)
{
  $split = explode('/', $s3_file_path);

  if (in_array('private', $split)) {
    $file_path = getenv('AWS_CLOUDFRONT_ENDPOINT') . $s3_file_path;

    $expires = time() + 86400;
    $private_key_filename = '/var/www/my-drupal/keys/pk-cloudfront.pem';
    $key_pair_id = getenv('AWS_S3_KEY_ID');

    $canned_policy_getters = Drupal::service('mymodule.aws.signature')
      -&gt;getCannedPolicyGetters($file_path, $private_key_filename, $key_pair_id, $expires);

    $url_settings['custom_GET_args'] = $canned_policy_getters;
  }
}