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.
- data/lib/resourceful/resource/cache.rb +12 -2
- data/lib/resourceful/version.rb +1 -1
- metadata +1 -1
@@ -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
|
data/lib/resourceful/version.rb
CHANGED