forget-me-not 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +1 -0
- data/README.md +8 -1
- data/lib/forget-me-not/cacheable.rb +3 -1
- data/lib/forget-me-not/memoizable.rb +3 -1
- data/lib/forget-me-not/version.rb +1 -1
- data/spec/cacheable_spec.rb +47 -0
- data/spec/memoizable_spec.rb +14 -0
- data/spec/spec_helper.rb +10 -6
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjQwMzE4NWI3Nzc0Zjc4ZWZjNWE3YmI0NjlkOGQxY2QxNDA0OGE4Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmI3MmViNjhiZDYxNjg1MGExNjliYmM0MGU2ZDY5NjZkYWE0ODYyZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTI0MDg1Yzc2M2U5YWU4OWM4OTA3NWY5NmQzMTEzYThiOWNlNjU0ZGRiZDY2
|
10
|
+
Y2ExODM0MjUxZmQwZmZkMWY1ZDc4NjQ1MjU0Y2ZkNjVhYWFhZWJiZjU2OWNj
|
11
|
+
MmRkZTE0YjQ1NWMzYWQwMDZhN2FiZjBlY2JmYjhmNzdkMjJjMWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzU3ZDRhNDhiMGJhNjAyNDk1YjY4ZTIxYjRhNzEzZGI1NzIxODg2ZWMwMDRm
|
14
|
+
Yzc0NDA3NDgwZjcwOTZlZDZlOTBmZTY0MzQzNTdmMDhlYTA1MDMzZDdmYzU5
|
15
|
+
ODY2NzFlYWYxODQxNzg4MjQ0ODU4MTY5YmNlOGY1YmM5MDNiZjk=
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -93,6 +93,9 @@ method if the method being memoized has arity > 0.
|
|
93
93
|
|
94
94
|
Memoization is a powerful tool, but like all powerful tools, needs to be used with knowledge and respect.
|
95
95
|
|
96
|
+
#### Blocks
|
97
|
+
You may not pass a block to a memoized method. Attempting to do so results in an error being raised.
|
98
|
+
|
96
99
|
#### Storage
|
97
100
|
By default, the memoization code stores results in a simple Hash based cache. If you have other requirements, perhaps
|
98
101
|
a thread-safe storage, then set the ForgetMeNot::Memoization.storage_builder property to a proc that will create a new
|
@@ -111,7 +114,8 @@ The basics are unsurprising:
|
|
111
114
|
cache :some_method
|
112
115
|
end
|
113
116
|
|
114
|
-
Like memoization, arguments are fully supported and will result in distinct storage to the cache.
|
117
|
+
Like memoization, arguments are fully supported and will result in distinct storage to the cache. Unlike memoization,
|
118
|
+
you do not need to call a with_args variant of the cache method.
|
115
119
|
|
116
120
|
To control warming the cache, implement the cache_warm method
|
117
121
|
|
@@ -156,6 +160,9 @@ key members.
|
|
156
160
|
Of course, every argument variation and every included instance property amplifies the potential amount of cache
|
157
161
|
memory that is consumed.
|
158
162
|
|
163
|
+
#### Blocks
|
164
|
+
You may not pass a block to a cached method. Attempting to do so results in an error being raised.
|
165
|
+
|
159
166
|
#### Storage
|
160
167
|
By default, the cache will attempt to use the Rails cache. If that isn't found, but ActiveSupport is available, a new
|
161
168
|
instance of MemoryStore will be used. Failing that, cache will raise an error.
|
@@ -32,7 +32,9 @@ module ForgetMeNot
|
|
32
32
|
instance_key = get_instance_key_proc(options[:include]) if options.has_key?(:include)
|
33
33
|
|
34
34
|
undef_method(method_name)
|
35
|
-
define_method(method_name) do |*args|
|
35
|
+
define_method(method_name) do |*args, &block|
|
36
|
+
raise 'Cannot pass blocks to cached methods' if block
|
37
|
+
|
36
38
|
cache_key = [
|
37
39
|
key_prefix,
|
38
40
|
(instance_key && instance_key.call(self)),
|
@@ -33,7 +33,9 @@ module ForgetMeNot
|
|
33
33
|
key_prefix = "/memoized_method_result/#{self.name}"
|
34
34
|
|
35
35
|
undef_method(method_name)
|
36
|
-
define_method(method_name) do |*args|
|
36
|
+
define_method(method_name) do |*args, &block|
|
37
|
+
raise 'Cannot pass blocks to memoized methods' if block
|
38
|
+
|
37
39
|
memoize_key = [
|
38
40
|
key_prefix,
|
39
41
|
method_name,
|
data/spec/cacheable_spec.rb
CHANGED
@@ -30,6 +30,12 @@ module ForgetMeNot
|
|
30
30
|
"method5({#{hash_arg.map { |k, v| "#{k}/#{v}" }.join '|' }})"
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.cache_warm(*args)
|
34
|
+
item = new
|
35
|
+
item.method1
|
36
|
+
item.method2(args.first)
|
37
|
+
end
|
38
|
+
|
33
39
|
cache_results :method1, :method2, :method3, :method4, :method5
|
34
40
|
end
|
35
41
|
|
@@ -93,6 +99,22 @@ module ForgetMeNot
|
|
93
99
|
|
94
100
|
expect(TestClass.count(:method1)).to eq 2
|
95
101
|
end
|
102
|
+
|
103
|
+
it 'should raise an error if called with a block on initial caching' do
|
104
|
+
foo = TestClass.new
|
105
|
+
expect do
|
106
|
+
foo.method1 {'a block'}
|
107
|
+
end.to raise_error 'Cannot pass blocks to cached methods'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should raise an error if called with a block after initial caching' do
|
111
|
+
foo = TestClass.new
|
112
|
+
foo.method1
|
113
|
+
expect do
|
114
|
+
foo.method1 {'a block'}
|
115
|
+
end.to raise_error 'Cannot pass blocks to cached methods'
|
116
|
+
end
|
117
|
+
|
96
118
|
end
|
97
119
|
|
98
120
|
describe 'cache arity-1 calls' do
|
@@ -193,6 +215,31 @@ module ForgetMeNot
|
|
193
215
|
expect(Cacheable.cachers_and_descendants & expected).to eq expected
|
194
216
|
end
|
195
217
|
|
218
|
+
it 'Cache Warming should call warmed methods' do
|
219
|
+
Cacheable.warm('foo')
|
220
|
+
|
221
|
+
expect(TestClass.count(:method1)).to eq 1
|
222
|
+
expect(TestClass.count(:method2)).to eq 1
|
223
|
+
expect(TestClass.count(:method3)).to eq 0
|
224
|
+
expect(TestClass.count(:method4)).to eq 0
|
225
|
+
expect(TestClass.count(:method5)).to eq 0
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'Cache Warming should call warm methods again' do
|
229
|
+
TestClass.new.method1
|
230
|
+
TestClass.new.method2('foo')
|
231
|
+
|
232
|
+
expect(TestClass.count(:method1)).to eq 1
|
233
|
+
expect(TestClass.count(:method2)).to eq 1
|
234
|
+
|
235
|
+
Cacheable.warm('foo')
|
236
|
+
|
237
|
+
expect(TestClass.count(:method1)).to eq 2
|
238
|
+
expect(TestClass.count(:method2)).to eq 2
|
239
|
+
expect(TestClass.count(:method3)).to eq 0
|
240
|
+
expect(TestClass.count(:method4)).to eq 0
|
241
|
+
expect(TestClass.count(:method5)).to eq 0
|
242
|
+
end
|
196
243
|
end
|
197
244
|
end
|
198
245
|
end
|
data/spec/memoizable_spec.rb
CHANGED
@@ -59,6 +59,20 @@ module ForgetMeNot
|
|
59
59
|
expect(MemoizeTestClass.count(:method1)).to eq 2
|
60
60
|
end
|
61
61
|
|
62
|
+
it 'should raise an error if called with a block on initial memoization' do
|
63
|
+
foo = MemoizeTestClass.new
|
64
|
+
expect do
|
65
|
+
foo.method1 {'a block'}
|
66
|
+
end.to raise_error 'Cannot pass blocks to memoized methods'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should raise an error if called with a block after initial memoization' do
|
70
|
+
foo = MemoizeTestClass.new
|
71
|
+
foo.method1
|
72
|
+
expect do
|
73
|
+
foo.method1 {'a block'}
|
74
|
+
end.to raise_error 'Cannot pass blocks to memoized methods'
|
75
|
+
end
|
62
76
|
end
|
63
77
|
|
64
78
|
describe 'memoize arity > 0 calls' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'bundler/setup'
|
3
|
-
require '
|
2
|
+
require 'simplecov'
|
4
3
|
|
5
|
-
|
6
|
-
require '
|
4
|
+
if ENV['TRAVIS']
|
5
|
+
require 'coveralls'
|
6
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter '/spec/'
|
11
|
+
end
|
10
12
|
|
13
|
+
require 'active_support/all'
|
14
|
+
require 'timecop'
|
11
15
|
require 'forget-me-not'
|
12
16
|
|
13
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forget-me-not
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koan Health
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Caching and Memoization Mixins
|
84
98
|
email:
|
85
99
|
- development@koanhealth.com
|