Rack::Cache is suitable as a quick drop-in component to enable HTTP caching
for Rack-based applications that produce freshness (
Cache-Control) and/or validation (
- Standards-based (see RFC 2616 / Section 13).
- Freshness/expiration based caching
- Vary support
- Portable: 100% Ruby / works with any Rack-enabled framework.
- Disk, memcached, and heap memory storage backends.
- Rack::Cache 1.0 was released on December 24, 2010. See the
CHANGESfile for details.
- How to use Rack::Cache with Rails 2.3 – it’s really easy.
- RailsLab’s Advanced HTTP Caching Screencast is a really great review of HTTP caching concepts and shows how to use Rack::Cache with Rails.
$ sudo gem install rack-cache
Or, from a local working copy:
$ git clone git://github.com/rtomayko/rack-cache.git $ rake package && sudo rake install
Rack::Cache is implemented as a piece of Rack middleware and can be used
with any Rack-based application. If your application includes a rackup
.ru) file or uses Rack::Builder to construct the application pipeline,
use as follows:
require 'rack/cache' use Rack::Cache, :verbose => true, :metastore => 'file:/var/cache/rack/meta', :entitystore => 'file:/var/cache/rack/body' run app
Assuming you’ve designed your backend application to take advantage of HTTP’s caching features, no further code or configuration is required for basic caching.
Configuration Options – how to set cache options.
Cache Storage Documentation – detailed information on the various storage implementations available in Rack::Cache and how to choose the one that’s best for your application.
Things Caches Do – an illustrated guide to how HTTP gateway caches work with pointers to other useful resources on HTTP caching.
GitHub Repository – get your fork on.
Mailing List – for hackers and users (
FAQ – Frequently Asked Questions about Rack::Cache.
RDoc API Documentation – Mostly worthless if you just want to use Rack::Cache in your application but mildly insightful if you’d like to get a feel for how the system has been put together; I recommend reading the source.
The overall design of Rack::Cache is based largely on the work of the internet standards community. The following resources provide a good starting point for exploring the basic concepts of HTTP caching:
Joe Gregorio’s Doing HTTP Caching Right