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.
@@ -1,5 +1,5 @@
1
1
  module Persistent
2
2
  class Cache
3
- VERSION = "0.3.4"
3
+ VERSION = "0.3.7"
4
4
  end
5
5
  end
@@ -78,24 +78,30 @@ module Persistent
78
78
  end
79
79
 
80
80
  def timestamp?(key)
81
- result = @storage.lookup_key(key)
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
- key = key.encode!(@encoding) if @encoding
90
- @storage.delete_entry(key)
91
- @storage.save_key_value_pair(key, value, timestamp)
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
- key = key.encode!(@encoding) if @encoding
96
- result = @storage.lookup_key(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?(key, result)
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
- key = key.encode!(@encoding) if @encoding
121
+ k = encode_if_requested(key)
116
122
  @storage.delete_entry(key)
117
123
  end
118
124
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persistent-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: