HTTP and server side cache integration for Grape and Rails
Switch branches/tags
Nothing to show
Clone or download
chytreg Merge pull request #7 from maruware/not_store_with_expired_in_0
do not use Rails.cache with expired in 0
Latest commit 62ed753 Oct 26, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib do not use Rails.cache with expired in 0 Oct 26, 2015
.gitignore First version Oct 2, 2013
Gemfile First version Oct 2, 2013
LICENSE.txt Update LICENSE.txt Dec 23, 2013
README.md Gem version badge Aug 27, 2014
Rakefile First version Oct 2, 2013
grape-rails-cache.gemspec Homepage in gemspec Oct 2, 2013

README.md

HTTP and server side cache integration for Grape and Rails Gem Version

Features

  • HTTP Headers cache, ETag, Cache-Control, If-None-Match
  • Server side cache for response body

Installation

Add this line to your rails application's Gemfile:

gem 'grape-rails-cache'

And then execute:

$ bundle

Usage

module MyApi < Grape::API
  format :json

  include Grape::Rails::Cache

  resources :posts do
    desc "Return a post"
    get ":id" do
      post = Post.find(params[:id])
      cache(key: "api:posts:#{post.id}", etag: post.updated_at, expires_in: 2.hours) do
        post # post.extend(PostRepresenter) etc, any code that renders response
      end
    end
  end
end

Contributing

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