code: protected void updateAuthorizationBasedOnCacheEntries(AuthorizationEntity authorization, String userId, String groupId,
                                                          Resource resource, String resourceId) {
      DbEntityManager dbManager = Context.getCommandContext().getDbEntityManager();
      List<AuthorizationEntity> list = dbManager.getCachedEntitiesByType(AuthorizationEntity.class);
      for (AuthorizationEntity authEntity : list) {
        boolean hasSameAuthRights = hasEntitySameAuthorizationRights(authEntity, userId, groupId, resource, resourceId);
        if (hasSameAuthRights) {
          int previousPermissions = authEntity.getPermissions();
          authorization.setPermissions(previousPermissions);
          dbManager.getDbEntityCache().remove(authEntity);
          return;
        }
      }
    }
docs: Searches through the cache, if there is already an authorization with same rights. If that's the case
  update the given authorization with the permissions and remove the old one from the cache.