forget-me-not 0.3.0 → 0.3.1
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/README.md +9 -1
- data/lib/forget-me-not/cacheable.rb +4 -2
- data/lib/forget-me-not/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDBlMjk4MDJmODI1YmU4Njc5NDA0ZjMxNjA3MmUwZTMyODgzMDg1YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Mjc4Yjg0YjcwOGJjOTE4NDVkZWQ3MDg0NWZhODhiMjI4N2RhNTFmNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmZhOTEwOTE3NGY2YzljODFhNzgzZTU0YjMwMzU3YjBhMjA1ZjEwYjZmN2Jh
|
10
|
+
MmFmYzM2YjFlOTQzNmExNzAxYjE3YzFhNzUyZmQ1MzZlMzQyYWMzZTNhODhh
|
11
|
+
M2EyY2M5Y2U0MjE3OTU2Zjk0ODg5OTUxOTQ4ZDNjOTUzY2NkYTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzRiN2VhZmNkYTBlNzYwY2YxYWY5MzM1MGE4MzQxYWU4YTllZGFlNTA4OGM5
|
14
|
+
MTgxZjlkYzhlYjdmNDU3ZWVjYTliMTk4MDZmNWJmOTBjZWViZDg5NTdiMWMy
|
15
|
+
YWFmNGU3MjI5ZmJiM2RkZTY3MDY4Y2FhNWI5ZWM1M2U1ZjhiNGE=
|
data/README.md
CHANGED
@@ -83,10 +83,14 @@ An additional caution is warranted when memoizing methods that take arguments.
|
|
83
83
|
in different results being memoized, if the set of arguments is unbounded, a great deal of memory can be consumed to
|
84
84
|
hold on to the results.
|
85
85
|
|
86
|
+
Memoization uses Ruby's hash() to differentiate arguments. **If you are using a custom class as an argument to a
|
87
|
+
memoized method, you must implement a valid hash method that is computed based upon the properties of the class.**
|
88
|
+
|
86
89
|
The easiest way to prevent stale results and excessive consumption of memory when memoizing is to ensure that two
|
87
90
|
things are true:
|
88
91
|
- The memoizing object has a finite, well-known life span (e.g., a request)
|
89
92
|
- If arguments are used, the set of possible arguments is bounded
|
93
|
+
- If arguments are used, every class must have a meaningful hash() method (the built in string, number, array, and hash all meet this criteria)
|
90
94
|
|
91
95
|
In order to draw attention to the potential issues with argument driven memoization, you must call the memoize_with_args
|
92
96
|
method if the method being memoized has arity > 0.
|
@@ -115,7 +119,11 @@ The basics are unsurprising:
|
|
115
119
|
end
|
116
120
|
|
117
121
|
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.
|
122
|
+
you do not need to call a with_args variant of the cache method. Caching uses Ruby's to_s() to create a string
|
123
|
+
representation of the argument (we can't use Ruby's hash, because the hash value depends upon the runtime).
|
124
|
+
|
125
|
+
**If you are using a custom class as an argument to a cached method, you must implement a valid to_s
|
126
|
+
method that is computed based upon the properties of the class.**
|
119
127
|
|
120
128
|
To control warming the cache, implement the cache_warm method
|
121
129
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
1
3
|
module ForgetMeNot
|
2
4
|
# Allows the cross-system caching of lengthy function calls
|
3
5
|
module Cacheable
|
@@ -39,10 +41,10 @@ module ForgetMeNot
|
|
39
41
|
key_prefix,
|
40
42
|
(instance_key && instance_key.call(self)),
|
41
43
|
method_name,
|
42
|
-
args.
|
44
|
+
Digest::SHA1.hexdigest(args.to_s)
|
43
45
|
].compact.join '/'
|
44
46
|
|
45
|
-
puts "key: #{cache_key}" if
|
47
|
+
puts "key: #{cache_key}" if defined?(Testing)
|
46
48
|
|
47
49
|
Cacheable.cache_fetch(cache_key) do
|
48
50
|
method.bind(self).call(*args)
|
data/spec/spec_helper.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
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-12-
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|