0

How would it be possible to unset the "Cache-Control: must-revalidate, no-cache, private" that drupal adds for logged in users, for a specific role? I want a specific role, to follow the non-authenticated users cache flow.

More specifically: We're allowing users to login to our site with a specific "guest" role. This allows them to visit 1 personalized page. Our goal is that non-authenticated user and the GUEST are being served cached nginx pages. However, all content is cached with NGINX and is served based on a combination of the SESS cookie(drupal sets that for logged in users) and the HEADERS for each response. All logged in users have the SESS cookie set, however the guest has an additional cookie that tells NGINX to ignore SESS. The second part of the response is related to the headers drupal sends. Drupal identifies that the user is logged in and sets everything to ""Cache-Control: must-revalidate, no-cache, private" instead of "Cache-Control: public, max-age 86400", that leads to our guests getting cache MISS instead of HIT

  • That header is only part of the story. It will tell browsers and other agents not to cache but altering it won't affect Drupal's own caching, which is much more significant. But trying to mess with that for a logged-in user is likely to have all sorts of weird side-effects. Please explain more about what you are trying to achieve. – Alfred Armstrong Oct 3 at 9:34
  • edited with a bigger description – Potney Switters Oct 3 at 9:45
  • Sounds like something you could sort out purely in nginx, I think, by rewriting the headers there. Not an expert but I have done similar in Varnish. – Alfred Armstrong Oct 3 at 10:20
  • 2
    You can change any header in a response event subscriber, see for example drupal.stackexchange.com/questions/188924/… – 4k4 Oct 3 at 11:08
  • The problem on that approach would be that you're overwriting the what drupal also believes should be cached or not. Thanks for the response though, it seems that it is the only alternative. – Potney Switters Oct 4 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.