I have a site that has traffic spikes from only a few sources. This site also needs to be able to show content to a user by guessing if they’ve just arrived on the site using PHPs $_SERVER[“HTTP_REFERER”].
Is it possible to include the value of req.http.referer in the varnish cache so that this behavior is on more of an individual user basis? I believe that some users are being showed the wrong content because of another user caching content with a different referrer value.
If you want the cache to be different on all referers possible the http protocols Vary-header is the solution for you. That will practically kill your cache hitrate if your traffic is not very uniform with referers from very few unique URLs.
What I think is a better solution is to remove the logic of guessing who is a new user from the php layer and add it to varnish. This can be done by setting a custom header to the request in the vcl_recv and then using that header to hash in vcl_hash by adding something like this to vcl_recv
And adding this to vcl_hash
When the user reaches your backend you can check the value of X-New-User from there instead of the referer.