README.md in active_memoize-1.1.1 vs README.md in active_memoize-2.0.0
- old
+ new
@@ -4,10 +4,13 @@
[![Build Status](https://travis-ci.org/drexed/active_memoize.svg?branch=master)](https://travis-ci.org/drexed/active_memoize)
ActiveMemoize provides an API caching and memoizing local
expensive calculations including those with parameters.
+The flexible API allows you to memoize results using class
+or instance level cache.
+
## Installation
Add this line to your application's Gemfile:
```ruby
@@ -22,34 +25,58 @@
$ gem install active_memoize
## Table of Contents
-* [Usage](#usage)
+* [Klass](#klass)
+* [Instance](#instance)
-## Usage
+## Klass
+Class level memoization is the quickest way to get up and running using your cache, but provides the least amount of flexibility. You can only cache results
+without access to any information about your cache.
+
```ruby
class Movies
+ extend ActiveMemoize::Klass
+ def random
+ HTTP.get('http://movies.com/any')
+ end
+
+ memoize :random
+
+ def search(title)
+ HTTP.get("http://movies.com?title=#{title}")
+ end
+
+ memoize :search, as: :find
+
+end
+```
+
+## Instance
+
+Instance level memoization is a more involved way to setup your cache, but provides the most amount of flexibility. You can access almost all methods
+in the `instance.rb` file.
+
+```ruby
+class Movies
+
def cache
- @cache ||= ActiveMemoize::Cache.new
+ @cache ||= ActiveMemoize::Instance.new
end
def all
- cache.memoize('custom_cache_key') do
- HTTP.get("http://movies.com/all")
- end
+ cache.memoize { HTTP.get("http://movies.com/all") }
end
def random
cache['random'] ||= HTTP.get('http://movies.com/any')
end
- def search(title, force = false)
- cache.clear if force
-
- cache.memoize do
+ def search(title)
+ cache.memoize(as: :find, refresh: !cache.empty?) do
HTTP.get("http://movies.com?title=#{title}")
end
end
end