No commit activity in last 3 years
No release in over 3 years
HTTP and server side cache integration for Grape and Rack applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

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