Rack::FunkyCache - Funky Cache for Rack

Blog Projects

Rack middleware which implements funky caching. Funky caching is technique popularized by PHP.net site. It was first mentioned by Rasmus Lerdorf in 2002. Middleware captures Rack output and caches it as static file to public directory. All subsequent requests are then served by Passenger and they never reach Rack.

For example when user requests /foo/bar for the first time, cache does not exists and request is passed to Rack. Rack generates the content and sends it to browser. Caching middleware captures the output and saves it as public/foo/bar.html. Passenger serves all subsequent request of /foo/bar using generated static file.


When using Bundler add the following to your Gemfile:

gem "rack-funky-cache", :require => "rack/funky-cache"

Otherwise install the gem from commandline and require it in your code:

gem install rack-funky-cache
require "rack/funky-cache"

Then it is just matter of using the middleware.

use Rack::FunkyCache

You can pass application root directory and cache directory as parameters. Defaults are:

use Rack::FunkyCache, :root => Dir.pwd, :path => "/public"

Fork me on GitHub

When asking a question include an URL to example page where the problem occurs. Even better is to make a Fiddle which demonstrates the problem. If you have longer code examples please use pastie.org.