spymemcached 0.2.0-java → 0.2.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/spymemcached.rb +7 -3
- data/spec/spymemcached_spec.rb +11 -0
- data/spymemcached.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/spymemcached.rb
CHANGED
@@ -18,7 +18,7 @@ class Spymemcached
|
|
18
18
|
|
19
19
|
def get(key, marshal = true)
|
20
20
|
value = @client.get(key)
|
21
|
-
marshal && value ?
|
21
|
+
marshal && value ? marshal_load(value) : value
|
22
22
|
end
|
23
23
|
|
24
24
|
def incr(key, by = 1)
|
@@ -38,7 +38,7 @@ class Spymemcached
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def multiget(keys, marshal = true)
|
41
|
-
Hash[*@client.getBulk(*keys).map { |k,v| [k, marshal ?
|
41
|
+
Hash[*@client.getBulk(*keys).map { |k,v| [k, marshal ? marshal_load(v) : v] }.flatten]
|
42
42
|
end
|
43
43
|
|
44
44
|
def add(key, value, expiration = 0, marshal = true)
|
@@ -55,6 +55,10 @@ class Spymemcached
|
|
55
55
|
|
56
56
|
private
|
57
57
|
def marshal(value, marshal)
|
58
|
-
marshal ? Marshal.dump(value) : value.to_s
|
58
|
+
marshal ? Marshal.dump(value).to_java_bytes : value.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def marshal_load(value)
|
62
|
+
Marshal.load(String.from_java_bytes(value))
|
59
63
|
end
|
60
64
|
end
|
data/spec/spymemcached_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require "action_view"
|
2
3
|
|
3
4
|
describe Spymemcached do
|
4
5
|
before do
|
@@ -115,4 +116,14 @@ describe Spymemcached do
|
|
115
116
|
@cache.add("a", {:a => "b"}, 0, false)
|
116
117
|
@cache.get("a", false).should == {:a => "b"}.to_s
|
117
118
|
end
|
119
|
+
|
120
|
+
# not sure exactly why, but ActionView::SafeBuffer
|
121
|
+
# is the only repeatable instance of this bug that
|
122
|
+
# I can find
|
123
|
+
it "supports marshalling ActionView::SafeBuffers" do
|
124
|
+
s = ActionView::SafeBuffer.new "<div class=\"story_2 clearfix\">\n <a href=\"/users/4\"><img alt=\"\" class=\"\" height=\"35\" src=\"http:///avatar_missing_35x35.gif\" title=\"\" width=\"35\" /></a>"
|
125
|
+
@cache.set("a", s)
|
126
|
+
@cache.get("a").should == s
|
127
|
+
@cache.multiget(["a"]).should == {"a" => s}
|
128
|
+
end
|
118
129
|
end
|
data/spymemcached.gemspec
CHANGED