Varnish Admin

Administer your varnish instance.

Varnish Admin ExpressionEngine Add-on

Administer your varnish instance with this ExpressionEngine add-on. Varnish Admin can:

  • Clear and warm cache automatically when channel or templates are added or updated (supports VCL expressions)
  • Clear and warm cache on via a module tag (useful for cron jobs)
  • Clear cache on demand in your ExpressionEngine backend
  • Set proper cache-control and expires header for Varnish to interpret using the included module tags

Usage

Requirements

Installation

Copy /third_party/cl_varnish_admin.ee_addon into /system/expressionengine/third_party.

Upgrading from 1.x

See the configuration section below but also note we will clear out your cache items since the new purge ability requires the full URL to be stored.

Configuration

Starting with version 2 Varnish Admin requires your Varnish server to be configured to include the following to support incoming requests to purge, ban, and refresh cached items. You can also choose to create an ACL in the Varnish configuration to protect your varnish server. Refer to [this article]https://www.varnish-software.com/static/book/Cache_invalidation.html for more information.

Sample default.vcl:

acl cache_admin_ips { "127.0.0.1"; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ cache_admin_ips) { error 405 "Not allowed"; } return (lookup); } if (req.request == "BAN") { if (!client.ip ~ cache_admin_ips) { error 405 "Not allowed"; } ban("obj.http.x-host ~ " + req.http.x-ban-host + " && obj.http.x-url ~ " + req.http.x-ban-url); error 200 "Cache Object Banned"; } if (req.request == "REFRESH") { set req.request = "GET"; set req.hash_always_miss = true; } } ... sub vcl_hit { if (req.request == "PURGE") { if (!client.ip ~ cache_admin_ips) { error 405 "Not allowed"; } purge; error 200 "Cache Object Purged"; } } ... sub vcl_miss { if (req.request == "PURGE") { purge; error 404 "Cache Object Not Found"; } } ... sub vcl_fetch { set beresp.http.x-url = req.url; set beresp.http.x-host = req.http.host; } ... sub vcl_deliver { unset resp.http.x-url; unset resp.http.x-host; }

Tags

{exp:cl_varnish_admin:expire}

Sets ExpressionEngine’s response Expire and Cache-control header for the given template for Varnish to interpret.

Parameters

  • when (required)

    Either the time in seconds or a string interpretable by strtotime.

    Examples:

    • {exp:cl_varnish_admin:expire when="tomorrow at 1:00am"} expires tomorrow at 1:00am (server timezone).
    • {exp:cl_varnish_admin:expire when="60"} expires in 60 seconds

{exp:cl_varnish_admin:parse_esi}

Tells varnish to process <esi:include… /> tags for a given template. This just sends a header “X-Parse-Esi: 1” to varnish so you’ll want to add the following to your Varnish configuration.

Varnish Configuration:

sub vcl_fetch { ... if (beresp.http.X-Parse-Esi) { set beresp.do_esi = true; } unset beresp.http.X-Parse-Esi; ... }

{exp:cl_varnish_admin:warm_expired_cached_items}

Warms expired cached items. Point your cronjob (or browser) to a template with this tag in it and it will run through the warming process for cached items. This is just an alternative to using the module action found in the settings.

Parameters

  • delay (default: 0)

    The delay between warm requests. Useful to prevent your server from getting hammered.

Help

Please login or sign-up first.

Change Log

v1.2.5 (Released 08-04-2014)

  • Warming can no longer get stuck in redirect loop.

  • Fixed Fatal error: Call to undefined method Cp::set_variable() in 2.9

v1.2.4 (Released 05-28-2014)

  • Fixed multisite settings overwriting each other.

v1.2.3 (Released 04-23-2014)

  • Fix duplicate entry when using search module

v1.2.2 (Released 04-03-2014)

  • Fixed installation issue with 2.5.3.

v1.2.1 (Released 04-03-2014)

  • Fixed issue where warm rule would only parse entry metadata.

  • Fixed issue where rule warm actions would duplicate when adding a new rule.

  • Added clear and warm ability to cached items listing.

  • Added cached items (estimated) listing to backend.

v1.2.0 (Released 01-03-2014)

  • Added {exp:cl_varnish_admin:parse_esi} tag.

  • Renamed on/in to when.

v1.1.1 (Released 12-30-2013)

  • Fixed: Installation fails with db SELECT error.

v1.1.0 (Released 12-29-2013)

  • Renamed {exp:cl_varnish_admin:cache} to {exp:cl_varnish_admin:expire} for readability.

v2.0.1 (Released 09-05-2014)

  • Fixed site ban not working as it was including the protocol.

  • Fixed template not refreshing cache when saving.

v2.0.0 (Released 09-04-2014)

  • Added purge, ban, and refresh functionality.

  • Fixed cached items from occasionally getting cleared out when warming them.

  • Implemented request driven (VCL) admin functionality.

v1.0.0 (Released 12-28-2013)

  • Released initial add-on.