fixed json cache bug on ajax home

This commit is contained in:
Bachir Soussi Chiadmi 2020-12-08 15:27:34 +01:00
parent e6c452629c
commit 72c83bfc93
1 changed files with 6 additions and 5 deletions

View File

@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Url;
@ -94,11 +95,11 @@ class AjaxHomeController extends ControllerBase {
'languages:language_content'
]
];
// $response = new JsonResponse();
// $response->setData($data);
$response = new CacheableJsonResponse($data);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($renderable));
$response = new JsonResponse();
$response->setData($data);
// $response = new CacheableJsonResponse($data);
// $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
// $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($renderable));
return $response;
}