Project

def_cache

0.0
No commit activity in last 3 years
No release in over 3 years
An agnostic ActiveSupport::Cache helper to enable easy caching of methods inside your classes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

DefCache

Version Dependencies Build Status Coverage Code Climate

A gem for dynamically caching methods in your classes

Installation

Add this line to your application's Gemfile:

gem 'def_cache'

And then execute:

$ bundle

Or install it yourself as:

$ gem install funky_cache

Usage

Basic

class MyClass
  include DefCache

  cache_method :my_foo_method

  def my_foo_method(bar, baz)
    "hello world"
  end
end

With Cache Options

class MyClass
  include DefCache

  cache_method :my_foo_method, expires_in: 30.minutes

  def my_foo_method(bar, baz)
    "hello world"
  end
end

With Dynamic Keys

class MyClass
  include DefCache

  cache_method :my_foo_method, keys: [:dyno_key]

  def my_foo_method(bar, baz)
    "hello world"
  end

  def dyno_key
    "value of key"
  end
end

With a custom store

defaults to Rails.cache in rails or :memory_store in ruby

class MyClass
  include DefCache

  cache_method :my_foo_method, with: :redis_store

  def my_foo_method(bar, baz)
    "hello world"
  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