Commit c4b09e4c authored by Rolf van de Krol's avatar Rolf van de Krol Committed by Fabian de Rijk
Browse files

Issue #3025723 by Rolf van de Krol: Caching for empty response

parent 7beed13c
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -104,8 +104,9 @@ class RestMenuItemsResource extends ResourceBase {
   *
   * @return \Drupal\rest\ResourceResponse
   *   The response containing a list of bundle names.
   *

   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function get($menu_name = NULL) {
    if ($menu_name) {
@@ -130,7 +131,13 @@ class RestMenuItemsResource extends ResourceBase {

      // Return if the menu does not exist or has no entries.
      if (empty($tree)) {
        return new ResourceResponse($tree);
        $response = new ResourceResponse($tree);

        if ($response instanceof CacheableResponseInterface) {
          $response->addCacheableDependency(new RestMenuItemsCacheableDependency($menu_name, $this->minDepth, $this->maxDepth));
        }

        return $response;
      }

      // Transform the tree using the manipulators you want.