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.
@@ -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
- self.cacheable = RPCMapper::Cacheable::Store.new(DEFAULT_LONGEVITY)
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.cacheable.read(key)
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.class.name}")
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.cacheable.write(key, fresh_value, (self.cache_expires) ? fresh_value[0].send(self.cache_expires) : Time.now + DEFAULT_LONGEVITY) unless fresh_value.empty?
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
@@ -3,7 +3,7 @@ module RPCMapper
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 5
6
+ TINY = 6
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
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: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Petticrew