0.0
No commit activity in last 3 years
No release in over 3 years
Add Varnish cache headers to controller actions. Automatically purge instances and models on after_create, after_update and after_destroy callbacks.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.0, < 6
 Project Readme

varnish_rails

Add Varnish cache headers to controller actions. Automatically purge instances and models on after_create, after_update and after_destroy callbacks.

Installation

  1. Add this line to your application's Gemfile:
gem 'varnish_rails'
  1. Run
$ bundle install
  1. Install VarnishRails
$ rails generate varnish_rails:install

Configuration

  1. Complete the config/initializers/varnish_rails.rb file.

Usage

  1. Add before_action :set_varnish_headers(max_age_in_seconds) in controllers that you wanna cache.

  2. Add calls to add_to_varnish_xkey_header(my_collection_or_item) in the cached controller actions to automatically generate the Varnish xkeys.

  3. For models that don't have to be purged automatically, add the following line is_updated_via_import to the model. You can then call MyModel::purge_cache_by_varnish_class_name to purge all cached pages that use this model.

  4. You can use Varnish ESI in your layout:

<% if @varnish_headers_are_set %>
  <esi:include src="/includes/header"/>
  <esi:remove>
    <%= render "/shared/header" %>
  </esi:remove>
<% else %>
  <%= render "/shared/header" %>
<% end %>

Contributing

  • Mario Bouchard

License

The gem is available as open source under the terms of the MIT License.