forget-me-not 0.3.2 → 0.3.2.1
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/lib/forget-me-not/cacheable.rb +36 -9
- data/lib/forget-me-not/version.rb +1 -1
- data/spec/cacheable_spec.rb +2 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTExZjc2Zjk2OWUzNWJjODVmOWU1MTM2MWUzMzJkNjk0YTIyYTNiMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTEwNTAwMDA3OWE1NTM3NWMwYzM4MTIwZTEwZTU4ZWQwY2FlZjljMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjE4NjNmOGMyNTI0MmFjZWYzYjJjNzczYjFlZTc4YzM0ZGQyNjI4MjI4NzJk
|
10
|
+
ZWZlMjdlOTk4MzMyMTgwZGY0M2RkODcwYjZlZGI2MjRmZjNiM2E2OGYyMDli
|
11
|
+
ZTNlZmMwYmYwYTI2ZTgyYzkzYjZjOGIwOGVlNzMxZGZlZWQ1Zjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2RjYzY2YWY3YWRlZGU2MmE1MDRmZTA5MjBjY2NmYWY3NDA1Mjg5MWU0MGM3
|
14
|
+
NzkwYWQ5MjkwMGM4NDE5ODkyZWFhYmVlYjI1MzFiOTllNWYxZTI4NzcyYmZk
|
15
|
+
YzhiNDdlM2RkYzQ4ZTY1NDI2OGQwNDJhYmI4ZTI4YjUxMGFmOTc=
|
data/CHANGELOG.md
CHANGED
@@ -31,29 +31,32 @@ 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 = 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
|
41
39
|
|
42
40
|
cache_key = [
|
43
41
|
key_prefix,
|
44
|
-
|
42
|
+
(instance_key && instance_key.call(self)),
|
45
43
|
method_name,
|
46
|
-
|
44
|
+
args.to_s,
|
47
45
|
].compact.join '/'
|
48
46
|
|
49
|
-
# 'Double bagging' the key makes sure that we do not overflow the range of a string hash key
|
50
47
|
cache_key_hash = Digest::SHA1.hexdigest(cache_key)
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
cache_hit = true
|
50
|
+
result = Cacheable.cache_fetch(cache_key_hash) do
|
51
|
+
cache_hit = false
|
55
52
|
method.bind(self).call(*args)
|
56
53
|
end
|
54
|
+
|
55
|
+
if Cacheable.log_cache_activity
|
56
|
+
Cacheable.logger.info "Cache #{cache_hit ? 'hit' : 'miss'} for #{cache_key} (#{cache_key_hash})"
|
57
|
+
end
|
58
|
+
|
59
|
+
result
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
@@ -122,6 +125,30 @@ module ForgetMeNot
|
|
122
125
|
end
|
123
126
|
end
|
124
127
|
|
128
|
+
class << self
|
129
|
+
attr_accessor :log_cache_activity
|
130
|
+
|
131
|
+
def logger
|
132
|
+
return @logger if defined?(@logger)
|
133
|
+
@logger = rails_logger || default_logger
|
134
|
+
end
|
135
|
+
|
136
|
+
def logger=(logger)
|
137
|
+
@logger = logger
|
138
|
+
end
|
139
|
+
|
140
|
+
def rails_logger
|
141
|
+
defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
|
142
|
+
end
|
143
|
+
|
144
|
+
def default_logger
|
145
|
+
logger = Logger.new(STDOUT)
|
146
|
+
logger.level = Logger::INFO
|
147
|
+
logger
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
125
152
|
private
|
126
153
|
def self.default_cache
|
127
154
|
rails_cache ||
|
data/spec/cacheable_spec.rb
CHANGED
@@ -65,6 +65,7 @@ module ForgetMeNot
|
|
65
65
|
|
66
66
|
describe Cacheable do
|
67
67
|
before do
|
68
|
+
Cacheable.log_cache_activity = true
|
68
69
|
Cacheable.cache = ActiveSupport::Cache::MemoryStore.new
|
69
70
|
TestClass.clear_calls
|
70
71
|
TestClass2.clear_calls
|
@@ -206,9 +207,7 @@ module ForgetMeNot
|
|
206
207
|
foo = TestClass2.new('general', 201312)
|
207
208
|
foo.method1
|
208
209
|
|
209
|
-
|
210
|
-
puts Cacheable.cache.instance_variable_get('@data').inspect
|
211
|
-
ugly_hash_key = "dd22a078b1a5e6e8cb2a0f8f0bf1105823103249"
|
210
|
+
ugly_hash_key = '90914de582dd73182e909216e27b3898120e07c3'
|
212
211
|
expect(Cacheable.cache.read(ugly_hash_key)).not_to be_nil
|
213
212
|
end
|
214
213
|
end
|
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.2
|
4
|
+
version: 0.3.2.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|