# See README for details. module HTTPCaching # If the client provided an HTTP timestamp, return a 304 Not Modified if the # content has not been modified since +latest_content_timestamp+. def if_cached_before(latest_content_timestamp) if request.env['HTTP_IF_MODIFIED_SINCE'] && latest_content_timestamp <= Time.rfc2822(request.env['HTTP_IF_MODIFIED_SINCE']) render :text => '304 Not Modified', :status => 304 else response.headers['Last-Modified'] = latest_content_timestamp.httpdate yield end end # Renders (using +options+) if the client's HTTP timestamp is older than # +latest_content_timestamp+. def render_if_cached_before(latest_content_timestamp, *options) if_cached_before latest_content_timestamp do render *options end end end module ActionController class Base include HTTPCaching end end