elgentos / magento2-varnish-extended
This extension extends the built-in Varnish functionalities
Installs: 1 455
Dependents: 0
Suggesters: 0
Security: 0
Stars: 45
Watchers: 5
Forks: 7
Open Issues: 9
Type:magento2-module
Requires
- magento/framework: >=103.0.7
- magento/module-page-cache: *
- dev-master
- 1.0.0
- dev-test_static_and_media_cache
- dev-test_debug_and_cookie_headers_pass
- dev-test_design_exceptions
- dev-test_health_check
- dev-test_status_codes
- dev-test_marketing_params
- dev-fix_parser
- dev-acl
- dev-ban
- dev-post_pass
- dev-grace
- dev-zero_grace
- dev-grace_backend_sick
- dev-readme_tests
- dev-pass_on_cookie_presence
- dev-ssl_offloaded_header
- dev-graphql
- dev-X-Magento-Vary
- dev-test-esi
- dev-xkey-soft-hard
- dev-bfcache
- dev-check_stripped_headers
- dev-final_vcltest_skeleton
- dev-include-test-variables
- dev-test_force_refresh
- dev-pretty_template
- dev-issue-7-part-three
- dev-vcl_clarification
- dev-add-flags-to-vcl
- dev-Backend-config-option-Enable-caching-of-Static-files
- dev-fix_sed
- dev-make_test
- dev-issue-7-part-two
- dev-php-compatibility
- dev-add-config-field-for-pass-on-cookie-presence
- dev-fix_placeholder
- dev-hash_always_miss
- dev-varnishdevenv
- dev-remove_debug_output
- dev-fixed-supported-varnish-versions
- dev-Allow-cache-purge-via-Ctrl-F-or-Cmd-Shift-R
- dev-x-magento-cache-debug-hit-grace
- dev-x-magento-purge-soft
- dev-acl_purge_for_loop
- dev-fix-php84-compat
- dev-update-vcl-command
- dev-issue-7
- dev-feature/use-xkey-option
- dev-feature/use-xkey-option-v2
- dev-feature/soft-purging-option
- dev-test_skeleton
This package is auto-updated.
Last update: 2025-06-06 17:59:19 UTC
README
Elgentos_VarnishExtended
This module aims to add some extra features to the Varnish capabilities in Magento.
Configurable tracking parameters
The core Magento VCL contains hard-coded marketing tracking parameters. Almost nobody changes them, but adding tracking parameters often used on your site highly increases hit rate.
This extension adds a field under Stores > Config > System > Full Page Cache > Varnish Configuration > Tracking Parameters in the backend to customize your own parameters.
IMPORTANT NOTE: this is not applied automatically! You need to use the optimized VCL:
bin/magento varnish:vcl:generate --export-version=6 ---input-file=vendor/elgentos/magento2-varnish-extended/etc/varnish6.vcl -output-file=/data/web/varnish6.vcl
varnishadm vcl.load new-custom-vcl /data/web/varnish6.vcl
varnishadm vcl.use new-custom-vcl
Marketing Parameters
Info message when removing marketing parameters
Marketing parameters in the URL have a negative effect on the hit rate of the (Varnish) cache. You can list the marketing parameters that Varnish should remove to improve the hit rate.
Don't worry, removing these parameters will not break Magento, because these URL parameters are only processed in your browser, not on the server.
Warning message when a marketing parameter matches our regular expression
Warning: you are trying to remove a marketing parameter from the URL that is also a filterable product attribute in Magento. Are you sure you want to remove it? Removing this parameter may prevent Magento from filtering on that attribute.
Checking the Varnish hit rate
If you use RUMVision and when on Hypernode or Maxcluster, you can view the historical Varnish hit rate in RUMvision.
Otherwise you can do it manually:
wget --quiet https://raw.githubusercontent.com/olivierHa/check_varnish/master/check_varnish.py
chmod +x check_varnish.py
./check_varnish.py -f MAIN.cache_hit,MAIN.cache_miss -r
A good hit-rate for a B2C store is around 80-90%. For B2B, this would be lower, depending on how closed-off your catalog is.
Auto-apply custom VCL
You can place it in your Git repo in app/etc/varnish6.vcl
and automate applying it through Deployer on each deploy with the following Deployer task.
desc('Auto-apply VCL when custom VCL exists');
task('vcl:auto-apply', function () {
if (test('[ -f {{release_path}}/app/etc/varnish6.vcl ]')) {
$timestamp = date('YmdHis');
run('{{bin/php}} {{release_path}}/bin/magento varnish:vcl:generate --export-version=6 --input-file={{release_path}}/app/etc/varnish6.vcl --output-file=/data/web/varnish6.vcl');
run('varnishadm vcl.load vcl' . $timestamp . ' /data/web/varnish6.vcl');
run('varnishadm vcl.use vcl' . $timestamp);
}
})->select('stage=production');
Contrary to popular belief, loading & activating ('using') a new VCL does not purge the cache objects already in Varnish. However, the new VCL might change how future requests are processed, which could result in cached items being evicted sooner or fetched differently.
Compatibility
Needs at least Magento 2.4.7 and Varnish 6.4.
If you run into your VCL being generated without curly braces inside for
and if
directives, please check if you haven't still applied patch MDVA-4344. If you're running a recent Magento version, this patch isn't needed and breaks generation of the VCL.
Running the test suite
The features of the VCL template are covered by a range of automated tests. To run the test suite, simply run make test
in the tests/varnish
folder:
cd tests/varnish make test
The make test
command will start a Docker container that has all the .vtc
files mounted and runs the varnishtest
command to run the tests.
This is the equivalent of running the following command in the tests/varnish
folder:
varnishtest *.vtc
This will run the entire test suite, but you can also run individual tests by running the following command:
cd tests/varnish
make test_single TEST=purge.vtc
This will only run the tests inside the purge.vtc
file, which is the equivalent of running varnishtest purge.vtc
.
More information about the varnishtest
program can be found on the varnish-cache.org documentation site. You will also find information on the Varnish Test Case syntax.