Problem/Motivation

I have enabled varnish and preview links on my site. And the varnish cache is working perfectly.

But when I create a preview link and when the preview link page loads, it sets a session cookie, which causes Varnish cache misses. And in a result other page performance decreases.

Steps to reproduce

Setup the varnish. Check varnish should be working.
Enable the Preview link module and generate the preview link for a node.
Hit the link in incognito and then open the other URL of site.
You will notice the page takes time to load and the varnish is also miss.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

Shani Maurya created an issue. See original summary.

shani maurya’s picture

Issue summary: View changes
shani maurya’s picture

larowlan’s picture

This powers the multiple entity support
We could theoretically remove it if you opted out of multiple entity support
However is caching preview links a good idea? You wouldn't want to cache drafts viewed by an admin

shani maurya’s picture

@larowlan We use preview links only for Node entities. When we open the preview link of any node in any browser and visit the other page of the site, the site is very slow which is causing more issues for us.

Session cookies get stored for preview links which causes the varnish miss cache.

We are okay to cache the preview links page. Can you help me with how I can disable the session cookies?

thank you!

larowlan’s picture

Title: Session cookie being set, breaking through Varnish cache. » Do not create a session if multiple entity support is disabled - impacts CDN hit rate

I mean it's hacky, but you could try putting this in the footer of your page in the meantime.

<img src="/preview-link/session-tokens/remove" height="1" width="1"/>

Preview link should still work if you're not making use of the 'multiple entities' functionality.

We need to fix it properly by preventing creating a session if 'multiple entities' is not enabled.

shani maurya’s picture

@larowlan the above solutions did not worked.

larowlan’s picture

Title: Do not create a session if multiple entity support is disabled - impacts CDN hit rate » Do not add the session cache context if multiple entity support is disabled or there is only 1:1 relationship between the entity and preview link

brayn7 made their first commit to this issue’s fork.

brayn7’s picture

.

brayn7’s picture

Version: 2.1.x-dev » 2.2.0-alpha2
acbramley’s picture

Version: 2.2.0-alpha2 » 2.x-dev
Status: Active » Needs work
Issue tags: +Needs tests
acbramley’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Added some test coverage for this, not sure if we need more. The test-only pipeline doesn't seem to be working properly but the test does fail on 2.x

larowlan’s picture

Looks great to me - thanks @acbramley

  • acbramley committed bd0790b5 on 2.x authored by brayn7
    fix: #3456231 Do not add the session cache context if multiple entity...
acbramley’s picture

Status: Needs review » Fixed

Thanks everyone

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.