Skip to main content
make the answer more general
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Two suggestions to improve caching:

  1. In case an entity existsEven if you havedon't want to make a decision to allow or deny access you can return a neutral access result with the correctto add cache datametadata.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addCacheTags(['my_entity_list']);
  }

postDelete() and postSave() are no longer necessary.

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addCacheTags(['my_entity_list']);
  }

postDelete() and postSave() are no longer necessary.

Two suggestions to improve caching:

  1. Even if you don't want to make a decision to allow or deny access you can return a neutral result to add cache metadata.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addCacheTags(['my_entity_list']);
  }

postDelete() and postSave() are no longer necessary.

added 1 character in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addcachetags>addCacheTags(['my_entity_list']);
  }

postDelete() and postSave() isare no longer necessary.

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addcachetags(['my_entity_list']);
  }

postDelete() and postSave() is no longer necessary.

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addCacheTags(['my_entity_list']);
  }

postDelete() and postSave() are no longer necessary.

added 1 character in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addcachetags(['my_entity_list'['my_entity_list']);
  }

postDelete() and postSave() is no longer necessary.

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addcachetags(['my_entity_list');
  }

postDelete() and postSave() is no longer necessary.

Two suggestions to improve caching:

  1. In case an entity exists you have to return a neutral access result with the correct cache data.

  2. The custom cache tag can be replaced by the list tag ENTITY_TYPE_list, which is invalidated automatically when entities are added or deleted.

The resulting code:

  public function access(AccountInterface $account) {
    if ($entity_does_not_exist) {
      return AccessResult::forbidden()->addCacheTags(['my_entity_list']);
    }
    return AccessResult::neutral()->addcachetags(['my_entity_list']);
  }

postDelete() and postSave() is no longer necessary.

Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217
Loading