forget-me-not 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/CHANGELOG.md +6 -0
- data/lib/forget-me-not/cacheable.rb +10 -5
- data/lib/forget-me-not/version.rb +1 -1
- data/spec/cacheable_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjkxMWJmMmY2NWMwYmZiN2FhNDFlZjY3N2E4NGMwYjljMGMyNzJjOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzczYmI5Yzc5MjIwMmY4NDc2OWQxNzkwYzlhNDllMTZmMDEyMmVhYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzYyY2IwZDkxZDQwNzYxMzFiNTAwMTc4NzE1NDgzNjE5NGFkM2VmNWQwOWEz
|
10
|
+
NThiMTgyNzVjOGZjMTg4YjIwMDkxOGMzYWJjZDA0ZjZmMjM5NDE2NWM2YWJh
|
11
|
+
MTJiOTMwOGZmNDBkODUxYmNhYWEyNDM2NDA4MWY2NGRjODYwOWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTVjZmM1NjJmZmZmNmIxZGJiZTBhODdjOGYxODMxNmFiN2E1ZDk0MTgxOThi
|
14
|
+
NGVlODkyNGFiODkwNjVlMWUzMDlmNDE2ZTBiNzk3YjViN2Y5NDE3OTEyNGM5
|
15
|
+
YzZkNTgyY2M2Mzc2MGIxYTVkMWU0MjcxODBiNjViOGQ4NzZkNmE=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.3.2.0 - Revise the method for computing keys in cacheable.
|
2
|
+
Need to use the digest for both the arguments and the instance properties.
|
3
|
+
|
4
|
+
## 0.3.1.0 - Fix the method for computing argument keys in cacheable.
|
5
|
+
Was using Ruby's hash(), but that varies by ruby runtime.
|
6
|
+
|
1
7
|
## 0.3.0.0 - Detect attempts to pass a block to cached or memoized methods and raise an error.
|
2
8
|
## 0.2.0.0 - Still pre release, but made a new method for memoizing methods with args.
|
3
9
|
## 0.1.0.0 - Pre Release
|
@@ -31,22 +31,27 @@ module ForgetMeNot
|
|
31
31
|
def define_cache_method(method, options)
|
32
32
|
method_name = method.name.to_sym
|
33
33
|
key_prefix = "/cached_method_result/#{self.name}"
|
34
|
-
|
34
|
+
instance_key_proc = get_instance_key_proc(options[:include]) if options.has_key?(:include)
|
35
35
|
|
36
36
|
undef_method(method_name)
|
37
37
|
define_method(method_name) do |*args, &block|
|
38
38
|
raise 'Cannot pass blocks to cached methods' if block
|
39
|
+
instance_key = instance_key_proc.call(self) if instance_key_proc
|
40
|
+
instance_key_hash = Digest::SHA1.hexdigest(instance_key.to_s) if instance_key
|
39
41
|
|
40
42
|
cache_key = [
|
41
43
|
key_prefix,
|
42
|
-
|
44
|
+
instance_key_hash,
|
43
45
|
method_name,
|
44
46
|
Digest::SHA1.hexdigest(args.to_s)
|
45
47
|
].compact.join '/'
|
46
48
|
|
47
|
-
|
49
|
+
# 'Double bagging' the key makes sure that we do not overflow the range of a string hash key
|
50
|
+
cache_key_hash = Digest::SHA1.hexdigest(cache_key)
|
48
51
|
|
49
|
-
|
52
|
+
puts "key: #{cache_key} (#{cache_key_hash})" if defined?(Testing)
|
53
|
+
|
54
|
+
Cacheable.cache_fetch(cache_key_hash) do
|
50
55
|
method.bind(self).call(*args)
|
51
56
|
end
|
52
57
|
end
|
@@ -55,7 +60,7 @@ module ForgetMeNot
|
|
55
60
|
def get_instance_key_proc(instance_key_methods)
|
56
61
|
instance_keys = Array.new(instance_key_methods).flatten
|
57
62
|
Proc.new do |instance|
|
58
|
-
instance_keys.map { |key| instance.send(key) }
|
63
|
+
instance_keys.map { |key| instance.send(key) }
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
data/spec/cacheable_spec.rb
CHANGED
@@ -201,6 +201,16 @@ module ForgetMeNot
|
|
201
201
|
expect(bar.method1).to eq '[general,201311].method1'
|
202
202
|
expect(TestClass2.count(:method1)).to eq 2
|
203
203
|
end
|
204
|
+
|
205
|
+
it 'Retains key consistency across process runs' do
|
206
|
+
foo = TestClass2.new('general', 201312)
|
207
|
+
foo.method1
|
208
|
+
|
209
|
+
puts Cacheable.cache.inspect
|
210
|
+
puts Cacheable.cache.instance_variable_get('@data').inspect
|
211
|
+
ugly_hash_key = "dd22a078b1a5e6e8cb2a0f8f0bf1105823103249"
|
212
|
+
expect(Cacheable.cache.read(ugly_hash_key)).not_to be_nil
|
213
|
+
end
|
204
214
|
end
|
205
215
|
|
206
216
|
describe 'cachers' do
|