Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rails: Cached pages with updated partials

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 gemfiles
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Appraisals
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 Rakefile
Octocat-spinner-32 Readme.md
Octocat-spinner-32 easy_esi.gemspec
Readme.md

Cached pages with updated partials.

Serve completely cached pages, but keep e.g. "Welcome <%= current_user %>" updated.
Does not influence not-cached actions.

Basics

Up and running in 23 seconds or money back!

Install (5s)

Rails 2 Version

gem install easy_esi

Action-cache the controller (5s)

class UsersController < ApplicationController
  caches_action :show
  enable_esi
end

Refactor partials that should stay updated (3s)

Has no effect for non-esi controllers! <%= render 'profile' %> IS NOW <%= esi_render 'profile' %>

<%= render 'profile', :local_variable => :foo %>
IS NOW
<%= esi_render :partial => 'profile', :locals => {:local_variable => :foo} %>

Realize that it's that simple (10s)

Behind the scenes

esi_render inserts an esi-include (<esi:include .... />).
an after_filter or easy-esi-rails-cache-hack replaces these by rendering the partial.
==> if you want to share view caches between controllers, call enable_esi in all of them (or in ApplicationController).

Comparison

Normally ESI means having an extra server that parses <esi> tags and then calls your app to render these partials. Which adds a whole lot of new problems(passing arguments, login, expiration, security...). On top of that it will slow down your application unless you do everything so perfect that it gets faster then a action-cached request (which is really hard...).

With 'hard' Esi, each <esi> tag causes a new, (yet small) request which needs to load all data (instance-variables) anew.
With easy-esi, each <esi> tag causes a partial to be rendered, inside the current context, re-using instance-variables.

Compared to normal ESI this means:

  • Testable caching
  • Enabled per-controller
  • No global changes
  • Deactivatable at any moment
  • before-filters still work
  • No extra server
  • No new actions
  • No duplicate server requests
  • No new configuration language
  • No purge requests
  • No external dependencies
  • ...

Author

Contributors

Michael Grosser
michael@grosser.it
License: MIT
Build Status

Something went wrong with that request. Please try again.