HTTP Caching plugin

Plugin details

Allows your Rails application to take advantage of the caching mechanisms built into HTTP 1.1 (i.e., 304 Not Modified return code).

Websitehttp://blog.codahale.com/2006/05/23/rails-plugin-http_caching/ Repositoryhttp://svn.codahale.com/http_caching/ Author Coda Hale Tags http, Cache LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.codahale.com/http_caching/

An example using send_data:

  def get_orders
    @photo = Photo.find(params[:id])
    if_cached_before @photo.updated_at do
      send_data @photo.data, :type => @photo.mime_type, :disposition => 'inline'
    end
  end


Another example, this time using a simple RHTML view:

  def get_user_profile
    @user = User.find(params[:id])
    render_if_cached_before @user.updated_at
  end


A slightly more complicated RHTML example:

  def get_orders
    render_if_cached_before Order.maximum(:updated_at), :layout => 'orders_feed', :action => 'all_orders'
  end


Or you can keep frequent refreshers from swamping your server:

  def shiny_object
    if_cached_before 10.minutes.ago do
      @shiny_object = ShinyObject.complicated_database_call(:woo => :hah)
    end
  end


You get the idea.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 7 months ago