HTTP and server side cache integration for Grape and Rack applications
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.gitignore first commit Dec 19, 2013
Gemfile first commit Dec 19, 2013
LICENSE first commit Dec 19, 2013
README.md 可以在缓存中写一段代码块 Jun 5, 2014
Rakefile first commit Dec 19, 2013
grape-shaman_cache.gemspec Upgrade to support grape-jbuilder 0.2.0 Apr 9, 2014

README.md

Grape::ShamanCache

Features

HTTP and server side cache integration for Grape and Jbuilder without Rails application.

If you're not familiar with HTTP caching, ETags and If-Modified-Since, here are some resources.

Installation

Add this line to your application's Gemfile:

gem 'grape-shaman_cache'

And then execute:

$ bundle

Or install it yourself as:

$ gem install grape-shaman_cache

remember to modify your config.ru file:

use Rack::ConditionalGet
use Rack::ETag

Usage

class Welcome < Grape::API

  include Grape::ShamanCache

  format :json
  formatter :json, Grape::Formatter::Jbuilder

  get :home, jbuilder: 'welcome/home' do
    @banners = Article.banner.without_gifts
    cache(key: [:v2, :home, @banners.last], expires_in: 2.hours) do
      @banners
    end
  end

end

or

class Welcome < Grape::API

  include Grape::ShamanCache

  format :json
  formatter :json, Grape::Formatter::Jbuilder

  get :home, jbuilder: 'welcome/home' do
    cache(key: [:v2, :home], expires_in: 2.hours) do
      @banners = Article.banner.without_gifts
    end
  end

end

Configuration

By default Grape::ShamanCache will use an instance of ActiveSupport::Cache::MemoryStore in a non-Rails application. You can configure it to use any other cache store.

Grape::ShamanCache.configure do |config|
  config.cache = ActiveSupport::Cache::FileStore.new("tmp/cache")
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request