diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index b51882c..77899fc 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -2,6 +2,8 @@ namespace Drupal\rest\Plugin\views\display; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Cache\CacheableJsonResponse; @@ -30,7 +32,7 @@ * returns_response = TRUE * ) */ -class RestExport extends PathPluginBase implements ResponseDisplayPluginInterface { +class RestExport extends PathPluginBase implements ResponseDisplayPluginInterface, CacheableDependencyInterface { /** * {@inheritdoc} @@ -277,7 +279,6 @@ public function collectRoutes(RouteCollection $collection) { */ public static function buildResponse($view_id, $display_id, array $args = []) { $build = static::buildBasicRenderable($view_id, $display_id, $args); - $build['#cache']['contexts'][] = "url.query_args:callback"; /** @var \Drupal\Core\Render\RendererInterface $renderer */ $renderer = \Drupal::service('renderer'); @@ -320,7 +321,7 @@ public function render() { // Allow for JSONP response. $callback = $this->view->getRequest()->get('jsonp') ?: $this->view->getRequest()->get('callback'); if ($callback) { - $this->view->element['#content_type'] = 'text/javascript'; + $this->view->element['#content_type'] = 'application/javascript'; $this->view->element['#jsonp_callback'] = $callback; } else { @@ -365,4 +366,25 @@ public function preview() { return $this->view->render(); } + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return Cache::PERMANENT; + } + + /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return ['url.query_args:callback', 'url.query_args:jsonp']; + } + + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + }