kelredd-resourceful 0.7.18 → 0.7.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,8 @@ module Resourceful
4
4
 
5
5
  attr_reader :store
6
6
 
7
+ EXPIRY_SECS = 30
8
+
7
9
  def self.key(host, verb, resource)
8
10
  "#{host}_#{verb}_#{resource}"
9
11
  end
@@ -21,11 +23,19 @@ module Resourceful
21
23
  end
22
24
 
23
25
  def read(key)
24
- @store[key]
26
+ entry = @store[key]
27
+ expired?(entry) ? nil : entry[:value]
25
28
  end
26
29
 
27
30
  def write(key, value)
28
- @store[key] = value
31
+ @store[key] = {:value => value, :expires => Time.now.to_i + EXPIRY_SECS}
32
+ end
33
+
34
+ private
35
+
36
+ def expired?(entry)
37
+ (entry.nil? || !entry.kind_of?(::Hash) || entry[:expires] < Time.now.to_i)
38
+
29
39
  end
30
40
 
31
41
  end
@@ -3,7 +3,7 @@ module Resourceful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 18
6
+ TINY = 19
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.18
4
+ version: 0.7.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding