Based on some VCL snippets I found on GitHub, this is probably the code that is responsible for creating the cache variation you want to get rid off:
sub vcl_hash {
if (req.http.cookie ~ "X-Magento-Vary=") {
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
}
# For multi site configurations to not cache each other's content
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
if (req.url ~ "/graphql") {
call process_graphql_headers;
}
# To make sure http users don't see ssl warning
if (req.http.X-Forwarded-Proto) {
hash_data(req.http.X-Forwarded-Proto);
}
}
The trick is to modify the following if-statement, and add a clause for when the client was identified as a bot:
if (req.http.cookie ~ "X-Magento-Vary=") {
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
}
This would result in the following if-statement:
if (req.http.cookie ~ "X-Magento-Vary=" && !req.http.is-bot) {
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
}
In vcl_recv
we can then write logic to identify the client as a bot. The easiest way is by adding a custom subroutine that contains this logic. That way we don't pollute the rest of the code.
sub check_bot {
if(req.http.User-Agent ~ "(bot|googlebot|crawler|spider|robot|crawling)") {
set req.http.is-bot = "true";
}
//Some other logic
}
The check_bot
subroutine will be triggered inside vcl_recv
:
sub vcl_recv {
call check_bot;
//The rest of the vcl_recv logic
}