method_cacher 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +5 -0
- data/README.md +27 -6
- data/lib/method_cacher/version.rb +1 -1
- data/method_cacher.gemspec +1 -0
- data/spec/method_cacher/base_spec.rb +0 -1
- data/spec/method_cacher/base_test_helper.rb +1 -1
- metadata +22 -10
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Method Cacher
|
1
|
+
# Method Cacher [![Build Status](https://secure.travis-ci.org/yaronw/method_cacher.png)](http://travis-ci.org/yaronw/method_cacher)
|
2
2
|
|
3
3
|
Wraps specified methods with a mechanism that caches the return values.
|
4
4
|
|
@@ -13,7 +13,8 @@ __Features:__
|
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
|
-
|
16
|
+
Run the command `gem install method_cacher`, or if used in a Rails project,
|
17
|
+
add the `method_cacher` gem your Gemfile and run the `bundle` command to install it.
|
17
18
|
|
18
19
|
```ruby
|
19
20
|
gem 'method_cacher'
|
@@ -23,11 +24,31 @@ __Requires Ruby 1.9.2 or later.__
|
|
23
24
|
|
24
25
|
## Configuration
|
25
26
|
|
26
|
-
|
27
|
+
Before utilized, method_cacher needs to be configured with a cache store for its use.
|
28
|
+
The cache store needs to be compatible with ActiveSupport::Cache.
|
29
|
+
|
30
|
+
Two styles of configuration are possible:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
MethodCacher.configure do |c|
|
34
|
+
c.caching_strategy = the_cache_store # Example: ActiveSupport::Cache.lookup_store(:memory_store)
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
and
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
MethodCacher.configure do
|
42
|
+
config.caching_strategy = the_cache_store # Example: ActiveSupport::Cache.lookup_store(:memory_store)
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
If used with Rails and no cache store is specified, method_cacher automatically uses the cache store configured with rails
|
47
|
+
through a call to `Rails.cache`.
|
27
48
|
|
28
49
|
## Usage
|
29
50
|
|
30
|
-
Include the
|
51
|
+
Include the `MethodCacher::Base` module in the class whose methods you wish to cache.
|
31
52
|
|
32
53
|
```ruby
|
33
54
|
include MethodCacher::Base
|
@@ -47,13 +68,13 @@ __Options:__
|
|
47
68
|
|
48
69
|
+ :singleton - Singleton methods to be cached are specified in an array of symbols passed through this option.
|
49
70
|
+ :obj\_key - A _proc_ that accepts the cached object as a single parameter. This _proc_ should return a value identifying this object.
|
50
|
-
If this option is not specified, the object key defaults to the value returned by
|
71
|
+
If this option is not specified, the object key defaults to the value returned by an instance method named _id_, which is convenient for usage
|
51
72
|
with ActiveRecord objects.
|
52
73
|
|
53
74
|
`cache_method` can take any number of instance or singleton methods at once.
|
54
75
|
|
55
76
|
Subsequent calls to `cache_method` are possible in order to specify additional methods to be cached.
|
56
|
-
Specifying
|
77
|
+
Specifying `:obj_id` multiple times results in the last one being used for the class.
|
57
78
|
|
58
79
|
`cache_method` can be called _before_ or _after_ the specified methods are defined.
|
59
80
|
|
data/method_cacher.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
gem.version = MethodCacher::VERSION
|
21
21
|
|
22
|
+
gem.add_development_dependency 'rake'
|
22
23
|
gem.add_development_dependency 'rspec'
|
23
24
|
gem.add_development_dependency 'supermodel'
|
24
25
|
gem.add_development_dependency 'activesupport'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_cacher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2152739300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152739300
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: rspec
|
16
|
-
requirement: &
|
27
|
+
requirement: &2152738880 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152738880
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: supermodel
|
27
|
-
requirement: &
|
38
|
+
requirement: &2152738460 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152738460
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: activesupport
|
38
|
-
requirement: &
|
49
|
+
requirement: &2152738040 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152738040
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: ruby-debug19
|
49
|
-
requirement: &
|
60
|
+
requirement: &2152737620 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,7 +65,7 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152737620
|
58
69
|
description: Easily cache instance and singleton (i.e. class) methods of ActiveRecord
|
59
70
|
or any object.
|
60
71
|
email:
|
@@ -66,6 +77,7 @@ files:
|
|
66
77
|
- .gitignore
|
67
78
|
- .rspec
|
68
79
|
- .rvmrc
|
80
|
+
- .travis.yml
|
69
81
|
- CHANGELOG.md
|
70
82
|
- Gemfile
|
71
83
|
- Gemfile.lock
|