ActiveMemoize
ActiveMemoize provides an API caching and memoizing local expensive calculations including those with parameters.
Installation
Add this line to your application's Gemfile:
gem 'active_memoize'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_memoize
Table of Contents
Usage
class Movies
def cache
@cache ||= ActiveMemoize::Cache.new
end
def all
cache.memoize('custom_cache_key') do
HTTP.get("http://movies.com/all")
end
end
def random
cache['random'] ||= HTTP.get('http://movies.com/any')
end
def search(title, force = false)
cache.clear if force
cache.memoize do
HTTP.get("http://movies.com?title=#{title}")
end
end
end
Contributing
Your contribution is welcome.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request