News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Dutch Web Alliance:
Using Varnish with ESI for a REST API
May 08, 2014 @ 10:23:35

In the latest post to the Dutch Web Alliance blog Bas de Nooijer looks at a handy use of ESI in Varnish as a part of the output for a REST API. ESI (Edge Side Includes) let you handle the caching and reuse of fragments of the output from your application and define different caching rules/techniques for each.

For a project I'm currently working on we are implementing a REST API. Performance for this API is critical, so amongst some other solutions Varnish is used. This was done with minimal effort, as the API already had the correct caching headers. There was a noticeable improvement, however I had the feeling this could be improved much more. I realised I can basically compare our REST API to any website, it uses HTTP in the same way. The main diffence is the content being JSON instead of HTML. Just like most websites, our API composes content in many different ways, for instance 'standalone' resources, collections of resources or embedded resources. In a website this would be a clear use case for ESI, so why not use it in our API?

He starts off by asking the question "why use ESI in an API" and compares the ESI method to the more traditional caching rules and handling. He includes two diagrams showing the flow of each handling type along with a brief description of how it would extract and combine the data. With the background out of the way, he gets into the code. He shows how to enable JSON caching in Varnish and the JSON tag information you'll need to include to tell Varnish to do its job.

0 comments voice your opinion now!
varnish rest api tutorial cache esi edge side include

Link: https://dutchweballiance.nl/techblog/using-varnish-with-esi-for-a-rest-api

blog comments powered by Disqus

Similar Posts

Odafe Ojenikoh's Blog: Interactive PHP CLI Applications using Zend Form

PHP-GTK Community Site: an IMAP Client & Screenshots with Gdk

Tibo Beijen's Blog: Catching PHP Exceptions: Except the unexpected

PHPBuilder.com: Talking to GitHub with PHP

Gergely Hodicska's Blog: What's new in PHP 5.3 - part 1: namespaces


Community Events

Don't see your event here?
Let us know!


laravel introduction podcast list framework php7 example opinion extension laravel5 security interview voicesoftheelephpant library language community series version api release

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework