varnish_rails
Add Varnish cache headers to controller actions. Automatically purge instances and models on after_create, after_update and after_destroy callbacks.
Installation
- Add this line to your application's Gemfile:
gem 'varnish_rails'
Run
$ bundle installInstall VarnishRails
$ rails generate varnish_rails:install
Configuration
- Complete the
config/initializers/varnish_rails.rbfile.
Usage
Add
before_action :set_varnish_headers(max_age_in_seconds)in controllers that you wanna cache.Add calls to
add_to_varnish_xkey_header(my_collection_or_item)in the cached controller actions to automatically generate the Varnish xkeys.For models that don't have to be purged automatically, add the following line
is_updated_via_importto the model. You can then callMyModel::purge_cache_by_varnish_class_nameto purge all cached pages that use this model.
Contributing
- Mario Bouchard
License
The gem is available as open source under the terms of the MIT License.