persistent-cache 0.3.4 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/persistent-cache/version.rb +1 -1
- data/lib/persistent-cache.rb +14 -8
- metadata +1 -1
data/lib/persistent-cache.rb
CHANGED
@@ -78,24 +78,30 @@ module Persistent
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def timestamp?(key)
|
81
|
-
|
81
|
+
k = encode_if_requested(key)
|
82
|
+
result = @storage.lookup_key(k)
|
82
83
|
return nil if result.nil? or result[1].nil?
|
83
84
|
Time.parse(result[1])
|
84
85
|
end
|
85
86
|
|
86
87
|
private
|
87
88
|
|
89
|
+
def encode_if_requested(key)
|
90
|
+
return key.encode(@encoding) if (not @encoding.nil?) and (key.is_a?(String))
|
91
|
+
key
|
92
|
+
end
|
93
|
+
|
88
94
|
def save_key_value_pair(key, value, timestamp = nil)
|
89
|
-
|
90
|
-
@storage.delete_entry(
|
91
|
-
@storage.save_key_value_pair(
|
95
|
+
k = encode_if_requested(key)
|
96
|
+
@storage.delete_entry(k)
|
97
|
+
@storage.save_key_value_pair(k, value, timestamp)
|
92
98
|
end
|
93
99
|
|
94
100
|
def lookup_key(key)
|
95
|
-
|
96
|
-
result = @storage.lookup_key(
|
101
|
+
k = encode_if_requested(key)
|
102
|
+
result = @storage.lookup_key(k)
|
97
103
|
return nil if nil_result?(result)
|
98
|
-
return nil if stale_entry?(
|
104
|
+
return nil if stale_entry?(k, result)
|
99
105
|
|
100
106
|
return result[0]
|
101
107
|
end
|
@@ -112,7 +118,7 @@ module Persistent
|
|
112
118
|
end
|
113
119
|
|
114
120
|
def delete_entry(key)
|
115
|
-
|
121
|
+
k = encode_if_requested(key)
|
116
122
|
@storage.delete_entry(key)
|
117
123
|
end
|
118
124
|
|