Problem/Motivation

Currently the autoComplete() function returns a JsonResponse - even when the minimum number of characters has not been hit.

Since it is a JsonResponse and not a CacheableJsonResponse, those requests are still made against origin and are uncacheable.

Proposed resolution

Return a CacheableJsonResponse instead of a JsonResponse with a cache context of url.query_args.

Ideally, the this could also be tied to a cache tag that would be associated with the suggestion table.

CommentFileSizeAuthor
#17 Screenshot from 2026-07-28 22-35-26.png608.04 KBbkelly

Issue fork suggestion-3593572

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jastraat created an issue. See original summary.

jastraat’s picture

I also added an automated test for the new functionality. In order to run that test, I needed to add a number of other elements like configuration schema that were missing.

jastraat’s picture

Status: Active » Needs review
samlerner’s picture

I tested this, and it works for me. Here's the headers when I ran curl -I "https://example.ddev.site/suggestion/autocomplete?q=foo" against a D11 site:

HTTP/2 200 
cache-control: must-revalidate, no-cache, private
content-language: en
content-type: application/json
date: Fri, 05 Jun 2026 20:23:42 GMT
expires: Sun, 19 Nov 1978 05:00:00 GMT
server: Apache/2.4.66 (Debian)
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-generator: Drupal 11 (https://www.drupal.org)

And after this patch:

HTTP/2 200 
cache-control: max-age=2764800, public
content-language: en
content-type: application/json
date: Fri, 05 Jun 2026 20:22:18 GMT
edge-cache-tag: k91I QBaD
etag: "1780690937"
expires: Sun, 19 Nov 1978 05:00:00 GMT
last-modified: Fri, 05 Jun 2026 20:22:17 GMT
server: Apache/2.4.66 (Debian)
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-acquia-purge-tags: ifek 80b8
x-acquia-site: crmftebp38200000
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-generator: Drupal 11 (https://www.drupal.org)

Note that cache-control changes to be enabled, and there are additional headers for cache tags.

Looks good to me!

samlerner’s picture

Status: Needs review » Reviewed & tested by the community
bkelly’s picture

Oh my gosh, my humble apologies, (renovating the house and didn't see all this action).

Now this sounds very interesting, I'll get up to speed with y'all tomorrow.

Thank you for your time.

- Bill Kelly

jastraat’s picture

Bill do you have questions? Just checking in :)

bkelly’s picture

Impressive work, really.

Great job solving something that wasn't even on my radar and adding the extra trimmings, (tests, schema...). Most excellent.

I've set aside today to familiarize myself with the new git.drupalcode.org workflow, (or some Drupal fanboy will freak out).

- Bill Kelly

  • bkelly committed 1fe6ee3e on 4.1.x authored by jastraat
    Issue #3593572: Add cache tag and make autocomplete response cacheable
    
bkelly’s picture

Hi Folks -

I think I've merged y'alls work into 4.1.x-dev. Since the new fancy Drupal CI doesn't appear to include all the individual commits I'm not sure yet.

Since I'm unfamiliar with the system I could have pooched this so I'm not sure if this statement applies, but as far as I'm concerned any CI system that doesn't include the branch history in a merge is fundamentally flawed, (or other words starting with "F". Grrrr...).

I'm going to review the merge and see about creating a new release.

Thank you for your time.

- Bill Kelly

jastraat’s picture

Thanks Bill! Would you mind updating the contribution record for this issue too?

jastraat’s picture

Status: Reviewed & tested by the community » Fixed

Updating to fixed since this was merged -

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jastraat’s picture

Hi Bill, could you please update the contribution record?

bkelly’s picture

StatusFileSize
new608.04 KB

Hi jastraat -

I believe I succeeded. Thanks for all the great work.

-- Bill Kelly

Screenshot of git.drupalcode.org commit.

jastraat’s picture

Thanks! :)