首页 > 解决方案 > 控制器结果声称提供了相关的缓存元数据,但检测到泄漏的元数据。Drupal 8

问题描述

我收到错误消息“控制器结果声称提供了相关的缓存元数据,但检测到了泄漏的元数据。” 在 Drupal 8.9.6 上。

这是有问题的功能/控制器:

public function getByType(Term $taxonomy_term) {
    $response = new CacheableJsonResponse();
    $response->addCacheableDependency($taxonomy_term);

    $metadata = new CacheableMetadata();
    $listCacheTags = $this->entityTypeManager()->getDefinition('product_option')->getListCacheTags();
    $metadata->addCacheTags($listCacheTags);
    $response->addCacheableDependency($metadata);

    $productOptionStorage = $this->entityTypeManager()->getStorage('product_option');
    $query = $productOptionStorage->getQuery()
      ->condition('field_product_variant.entity.field_product_type_', $taxonomy_term->id());
    $ids = $query->execute();
    $results = $productOptionStorage->loadMultiple($ids);

    $data = [];
    $skip = [
      'field_layer_colors',
      'field_product_variant',
      'field_supporting_colors',
    ];
    /** @var ProductOptionEntity $result */
    foreach ($results as $result) {
      $response->addCacheableDependency($result);
      $option = ProductSerializer::serializeEntityReferenceField($result, $skip);
      $option['field_product_variant'] = $result->get('field_product_variant')->target_id;
      $data[] = $option;
    }

    $response->setData($data);
    return $response;

有任何想法吗?

谢谢!

标签: phpdrupaldrupal-8

解决方案


推荐阅读