Feature #13389

Support ability for reverse proxies, like Varnish, to cache content that's not in the default culture

Added by Mike Cantelon over 1 year ago. Updated over 1 year ago.

Status:QA/ReviewStart date:07/19/2020
Priority:MediumDue date:
Assignee:-% Done:

0%

Category:Performance / scalability
Target version:Release 2.7.0
Google Code Legacy ID: Tested version:
Sponsored:No Requires documentation:

Description

Varnish currently can only cache content the default culture because sessions are used to store a user's culture and sessions rely on cookies, which Varnish strip out of backend requests. Modify AtoM, and provide sample Varnish configuration modifications, to support the caching of content that's not in the default culture.


Related issues

Related to Access to Memory (AtoM) - Task #13405: Update Docker VCL to allow switching of language QA/Review 08/15/2020

History

#1 Updated by Mike Cantelon over 1 year ago

Strategy for supporting this in Varnish:

1) Use a separate cookie (rather than a session) to allow a specified culture to persist across requests from a given user

2) Don't cache requests in which the culture is being changed so a cookie specifying the culture can be set by AtoM's response

3) When a culture cookie is set then set an HTTP header value to the value of the cookie (the culture)

4) Incorporate the value of the HTTP header value into the hash key used to store cached entries (so different language versions of the same page can be cached)

The setting of the cookie in step 2 might be able to be done without relaying a request to AtoM but the performance gains of this would be negligible.

#2 Updated by Mike Cantelon over 1 year ago

Implementation of this strategy in more detail:

A) AtoM must:

  • Set a cookie when the culture is changed so the user's culture can persistantly be known by Varnish
  • Change a user's language, if the X-Atom-Language HTTP header is set, to the value of the header

B) Varnish must:

  • Allow requests to change culture to not be cached so a culture cookie can be set
  • Prevent the culture cookie from being stripped out in responses where culture cookie's been set
  • Set an HTTP header to the value of the culture cookie
  • Incorporate the value of the culture cookie into the cache key

#3 Updated by Mike Cantelon over 1 year ago

These changes need to be made in AtoM:

1) When culture is changed by a user then set the "atom_culture" cookie (so choice of culture persists across browser requests)

2) When culture is specified by the X-Atom-Language HTTP header then set AtoM culture to it

These are made in this pull request: https://github.com/artefactual/atom/pull/1161

These changes need to be made to the Varnish VCL:

1) Import cookie module

    import cookie;

2) Don't cache requests where sf_culture is set

Add to vcl_recv, near the beginning:

    if (req.url ~ "sf_culture") {
        return(pass);
    }

3) Set the X-Atom-Culture HTTP header to the value of the atom_language cookie

Add to vcl_recv, after the previous snippet:

    cookie.parse(req.http.cookie);
    set req.http.X-Atom-Culture = cookie.get("atom_culture");

4) Incorporate the culture into the hash key

Add to vcl_hash, at the end:

    hash_data(req.http.X-Atom-Culture);

5) Don't remove set cookie HTTP headers from the response when culture's being set:

Add to vcl_backend_response:

    if (bereq.url !~ "sf_culture")  {
       unset beresp.http.set-cookie;
    }

#4 Updated by Mike Cantelon over 1 year ago

This solution seems to work. I'll re-test (applying the VCL modifications step-by-step from scratch) to make sure. Likely another 3-6 hours to completion assuming code review back-and-forth isn't too involved.

#5 Updated by Mike Cantelon over 1 year ago

  • Category set to Performance / scalability
  • Assignee set to Mike Cantelon

#6 Updated by Mike Cantelon over 1 year ago

  • Status changed from New to QA/Review
  • Assignee deleted (Mike Cantelon)

Merged into qa/2.x.

I'll be making a separate issue/PR for changes to the Docker VCL to work with this.

#7 Updated by Mike Cantelon over 1 year ago

  • Related to Task #13405: Update Docker VCL to allow switching of language added

Also available in: Atom PDF