Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dkd-dobberkau/03950ed0f3311645c89153d9769ebcb5 to your computer and use it in GitHub Desktop.
Save dkd-dobberkau/03950ed0f3311645c89153d9769ebcb5 to your computer and use it in GitHub Desktop.
How a TYPO3 extension for Varnish integration was born from a flash of inspiration.
In 2013, my former employer snowflake and Redpill Linpro, the company behind Varnish at the time, agreed to work together. Part of this contract was that I was allowed to attend a Varnish course in Oslo with two colleagues, in order to give courses in Germany, Austria and Switzerland as a certified Varnish trainer afterwards.
Not only the social program remained in my good memory, but also in the course we could learn a lot of new things, although we had already actively used Varnish before. Besides the successful certification of all participants, the idea for the TYPO3 Varnish Extension can be called a great achievement of these 3 days.
TYPO3 and Varnish
Up to this point a TYPO3 extension for Varnish already existed. The process of this extension was that when changing a page in the TYPO3 backend, all URLs belonging to this page were collected and then sent individually to Varnish for deletion. This was not very practical on most of our installations, so we often decided not to use an extension. Instead, we manually set the cache duration in Varnish to be short enough that it didn't cause a big loss of convenience, but this in turn caused other disadvantages.
Idea and implementation
Back to the course in Oslo. One module was about how to use additional HTTP headers from the application to send data to Varnish, and then use them to perform cache invalidation based on them. Already while reading the task it was clear to me that this concept was a perfect fit for building the TYPO3 cache based on the page ID.
Back in Switzerland I immediately started the implementation. A short time later the first version was available in the extension repository with the following functions:
the TYPO3 frontend sends the current page ID as HTTP header to Varnish
the TYPO3 backend, respectively the caching framework, sends the page ID of a changed page to Varnish
the corresponding Varnish configuration template ensures that
the page ID header is stored in Varnish, but not sent to the client
in case of a reported change, all pages with the corresponding Page ID are discarded
I released this first version of the extension, at that time for TYPO3 4.5, on August 14, 2013. In the meantime, various features have been added and bugs patched in 14 versions. A special thanks goes to the TYPO3 community, many changes were contributed by individuals or companies and could be published by me directly after testing.
Outlook
Meanwhile I rarely get the chance to program something with PHP. The constant adaptation of the extension to current TYPO3 versions is therefore always a new, but still very interesting challenge. Also I can always count on great help from colleagues, customers or third parties from the TYPO3 community (Thanks Christoph, Benni, Daniel and many more!), which makes the whole thing much easier.
At the moment, the focus is mainly on integrating the ongoing adjustments to the TYPO3 core in a meaningful way. For example, in the last version the remaining TYPO3 hooks were replaced by PSR-14 events, and next Varnish commands will be issued via PSR-7. Another major change will be the move away from Page ID to the new TYPO3 Cache Tags. If you are interested in technical details, you can find the current planning in the TYPO3 Varnish GitLab project.
Until today this extension has been downloaded about 16'000 times from the extension repository and has become the defacto standard for Varnish integration in TYPO3. I am looking forward to the future development and thank all users and helpers who make this possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment