Representable::Cache
provide cache feature for Representable
Installation
Add this line to your application's Gemfile:
gem 'representable-cache'
And then execute:
$ bundle
Or install it yourself as:
$ gem install representable-cache
Usage
Default Configuration
Representable::Cache.cache_engine = Dalli::Client.new('localhost:11211', :namespace => "app_v1")
Representable::Cache.default_cache_key = [:id, :updated_at]
Representable::Cache.enable = false # Default: true
Setup
require 'representable/json'
require 'representable/cache'
module SongRepresenter
include Representable::JSON
include Representable::Cache
property :title
property :track
end
settings
module SongRepresenter
include Representable::JSON
include Representable::Cache
property :title
property :track
representable_cache :cache_key => :id, :cache_name => "Brand",
:version => "v1"
end
options:
- cache_key: could be symble or array, will use default_cache_key if not set
- cache_name: default: module or class name
- version: version name, you can invalid old cache by bump cache version
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request