0

Hi I've created a module with a controller but now i'm getting this message;

The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Cache\CacheableJsonResponse.

this is my code:

$cpdata=[];
$cpdata[]=[
  'image'=>'image.png',
  'title'=>'item01',
  'price'=>'30',
];

$cache_options['#cache'] = [
  'contexts' => ['url',],
  'tags' => ['node_list:Content']
];
$response = new CacheableJsonResponse($cpdata);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($cache_options));
return $response;

is some way to fix this issue? I appreciate your help

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.