rack-cache 0,0 travis-ci ruby Rubygems

Real HTTP Caching for Ruby Web Apps

Rack::Cache

Rack::Cache is suitable as a quick drop-in component to enable HTTP caching for Rack-based applications that produce freshness (Expires, Cache-Control) and/or validation (Last-Modified, ETag) information:

  • Standards-based (RFC 2616)
  • Freshness/expiration based caching
  • Validation (If-Modified-Since / If-None-Match)
  • Vary support
  • Cache-Control: public, private, max-age, s-maxage, must-revalidate, and proxy-revalidate.
  • Portable: 100% Ruby / works with any Rack-enabled framework
  • Disk, memcached, and heap memory storage backends

For more information about Rack::Cache features and usage, see:

http://rtomayko.github.com/rack-cache/

Rack::Cache is not overly optimized for performance. The main goal of the project is to provide a portable, easy-to-configure, and standards-based caching solution for small to medium sized deployments. More sophisticated / high-performance caching systems (e.g., Varnish, Squid, httpd/mod-cache) may be more appropriate for large deployments with significant throughput requirements.

Installation

gem install rack-cache

Basic Usage

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, simply require and use as follows:

require 'rack/cache'

use Rack::Cache,
  metastore:    'file:/var/cache/rack/meta',
  entitystore:  'file:/var/cache/rack/body',
  verbose:      true

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.

Using with Rails

Add this to your config/environment.rb:

config.middleware.use Rack::Cache,
   verbose:     true,
   metastore:   'file:/var/cache/rack/meta',
   entitystore: 'file:/var/cache/rack/body'

You should now see Rack::Cache listed in the middleware pipeline:

rake middleware

See the following for more information:

http://snippets.aktagon.com/snippets/302-how-to-setup-and-use-rack-cache-with-rails

Using with Dalli

Dalli is a high performance memcached client for Ruby. More information at: https://github.com/mperham/dalli

require 'dalli'
require 'rack/cache'

use Rack::Cache,
  verbose:  true,
  metastore:    "memcached://localhost:11211/meta",
  entitystore:  "memcached://localhost:11211/body"

run app

Noop entity store

Does not persist response bodies (no disk/memory used).
Responses from the cache will have an empty body.
Clients must ignore these empty cached response (check for X-Rack-Cache response header).
Atm cannot handle streamed responses, patch needed.

require 'rack/cache'

use Rack::Cache,
 verbose: true,
 metastore: <any backend>
 entitystore: "noop:/"

run app

License: MIT
Build Status

Related Repositories

redis-store

redis-store

Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks ...

rack-cache

rack-cache

Real HTTP Caching for Ruby Web Apps ...

garner

garner

A set of Rack middleware and cache helpers that implement various caching strategies. ...

rack-worker

rack-worker

Rack middleware that implements the Worker Pattern to process generic GET requests in the background and only serve them from a cache. ...

rest-client-components

rest-client-components

RestClient on steroids ! Easily add one or more Rack middleware around RestClient to add functionalities such as transparent caching (Rack::Cache), transparent logging, etc. ...


Top Contributors

rtomayko grosser amatriain rmm5t atzkey mezis nakajima aughr jamesruston kyledrake spastorino tekwiz arunagw alau abargnesi thisduck oggy jtblin josepjaume josh karmi nirvdrum hexgnu boone mje113 mperham mislav fxn artygus winton

Releases

-   v1.6.1 zip tar
-   v1.6.0 zip tar
-   v1.5.1 zip tar
-   v1.5.0 zip tar
-   v1.4.3 zip tar
-   v1.4.2 zip tar
-   v1.4.1 zip tar
-   v1.4.0 zip tar
-   v1.3.1 zip tar
-   v1.3.0 zip tar
-   1.2 zip tar
-   1.1 zip tar
-   1.0.3 zip tar
-   1.0.2 zip tar
-   1.0.1 zip tar
-   1.0 zip tar
-   0.5.3 zip tar
-   0.5.2 zip tar
-   0.5.1 zip tar
-   0.5.0 zip tar
-   0.4.0 zip tar
-   0.3.0 zip tar
-   0.2.0 zip tar