Rack::NonCache
Rack::NonCache is a rack middleware that disables HTTP browser caching.
Installation
From Gem:
$ sudo gem install rack-noncache
With a local working copy:
$ git clone git://github.com/dsaenztagarro/rack-noncache.git
$ rake package && sudo rake install
Basic Usage
Rack::NonCache 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/noncache'
use Rack::NonCache,
:metastore => 'file:/var/cache/rack/meta',
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::NonCache,
:whitelist => ['/path/to/non/caching/url', ...,
Regexp.new(/^\/path\/to\/non\/caching\/url/)]
or:
config.middleware.use Rack::NonCache,
:blacklist => ['/path/to/non/caching/url', ...,
Regexp.new(/^\/path\/to\/non\/caching\/url/)],
You should now see Rack::NonCache
listed in the middleware pipeline:
rake middleware
See the following for more information:
http://snippets.aktagon.com/snippets/302
Links
GitHub: http://github.com/dsaenztagarro/rack-noncache/
License
Copyright (c) 2014 David Saenz Tagarro
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.