rpc-mapper 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rpc_mapper/cacheable.rb +12 -6
- data/lib/rpc_mapper/version.rb +1 -1
- metadata +3 -3
data/lib/rpc_mapper/cacheable.rb
CHANGED
@@ -8,20 +8,25 @@ module RPCMapper::Cacheable
|
|
8
8
|
|
9
9
|
# TRP: Default to a 5 minute cache
|
10
10
|
DEFAULT_LONGEVITY = 5*60
|
11
|
+
@@cache_store = nil
|
11
12
|
|
12
|
-
def reset_cache_store
|
13
|
-
|
13
|
+
def reset_cache_store(default_longevity=DEFAULT_LONGEVITY)
|
14
|
+
@@cache_store = RPCMapper::Cacheable::Store.new(default_longevity)
|
15
|
+
end
|
16
|
+
|
17
|
+
def cache_store
|
18
|
+
@@cache_store
|
14
19
|
end
|
15
20
|
|
16
21
|
protected
|
17
22
|
|
18
23
|
def fetch_records_with_caching(options={})
|
19
24
|
key = Digest::MD5.hexdigest(self.to_s + options.to_a.sort { |a,b| a.to_s.first <=> b.to_s.first }.inspect)
|
20
|
-
cache_hit = self.
|
25
|
+
cache_hit = self.cache_store.read(key)
|
21
26
|
get_fresh = options.delete(:fresh)
|
22
27
|
|
23
28
|
if cache_hit && !get_fresh
|
24
|
-
self.read_adapter.log(options, "CACHE #{self.
|
29
|
+
self.read_adapter.log(options, "CACHE #{self.name}")
|
25
30
|
cache_hit.each { |fv| fv.fresh = false.freeze }
|
26
31
|
cache_hit
|
27
32
|
else
|
@@ -29,7 +34,7 @@ module RPCMapper::Cacheable
|
|
29
34
|
|
30
35
|
# TRP: Only store in cache if record count is below the cache_record_count_threshold (if it is set)
|
31
36
|
if !self.cache_record_count_threshold || fresh_value.size <= self.cache_record_count_threshold
|
32
|
-
self.
|
37
|
+
self.cache_store.write(key, fresh_value, (self.cache_expires) ? fresh_value[0].send(self.cache_expires) : Time.now + DEFAULT_LONGEVITY) unless fresh_value.empty?
|
33
38
|
fresh_value.each { |fv| fv.fresh = true.freeze }
|
34
39
|
end
|
35
40
|
|
@@ -38,7 +43,8 @@ module RPCMapper::Cacheable
|
|
38
43
|
end
|
39
44
|
|
40
45
|
def enable_caching(options)
|
41
|
-
reset_cache_store
|
46
|
+
reset_cache_store unless cache_store
|
47
|
+
self.cacheable = true
|
42
48
|
self.cache_expires = options[:expires]
|
43
49
|
self.cache_record_count_threshold = options[:record_count_threshold]
|
44
50
|
end
|
data/lib/rpc_mapper/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpc-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Petticrew
|