large_object_store 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Readme.md +1 -0
- data/lib/large_object_store/version.rb +1 -1
- data/lib/large_object_store.rb +23 -14
- data/spec/large_object_store_spec.rb +12 -2
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
data/lib/large_object_store.rb
CHANGED
@@ -20,18 +20,22 @@ module LargeObjectStore
|
|
20
20
|
|
21
21
|
# store number of pages
|
22
22
|
pages = (value.size / LIMIT.to_f).ceil
|
23
|
-
@store.write("#{key}_0", pages, options)
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
break if slice.size == 0
|
24
|
+
if pages == 1
|
25
|
+
@store.write("#{key}_0", value, options)
|
26
|
+
else
|
27
|
+
@store.write("#{key}_0", pages, options)
|
30
28
|
|
31
|
-
|
32
|
-
page
|
33
|
-
|
29
|
+
# store object
|
30
|
+
page = 1
|
31
|
+
loop do
|
32
|
+
slice = value.slice!(0, LIMIT)
|
33
|
+
break if slice.size == 0
|
34
34
|
|
35
|
+
@store.write("#{key}_#{page}", slice, options)
|
36
|
+
page += 1
|
37
|
+
end
|
38
|
+
end
|
35
39
|
true
|
36
40
|
end
|
37
41
|
|
@@ -40,11 +44,16 @@ module LargeObjectStore
|
|
40
44
|
pages = @store.read("#{key}_0")
|
41
45
|
return if pages.nil?
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
data = if pages.is_a?(String)
|
48
|
+
pages
|
49
|
+
else
|
50
|
+
# read sliced data
|
51
|
+
keys = Array.new(pages).each_with_index.map{|_,i| "#{key}_#{i+1}" }
|
52
|
+
slices = @store.read_multi(*keys).values
|
53
|
+
return nil if slices.compact.size < pages
|
54
|
+
slices.join("")
|
55
|
+
end
|
56
|
+
Marshal.load(data)
|
48
57
|
end
|
49
58
|
|
50
59
|
def fetch(key, options={})
|
@@ -47,11 +47,16 @@ describe LargeObjectStore do
|
|
47
47
|
store.read("a").size.should == 10_000_000
|
48
48
|
end
|
49
49
|
|
50
|
-
it "passes options" do
|
51
|
-
store.store.should_receive(:write).with(anything, anything, :expires_in => 111)
|
50
|
+
it "passes options when caching small" do
|
51
|
+
store.store.should_receive(:write).with(anything, anything, :expires_in => 111)
|
52
52
|
store.write("a", "a", :expires_in => 111)
|
53
53
|
end
|
54
54
|
|
55
|
+
it "passes options when caching big" do
|
56
|
+
store.store.should_receive(:write).with(anything, anything, :expires_in => 111).exactly(3).times
|
57
|
+
store.write("a", "a"*1_200_000, :expires_in => 111)
|
58
|
+
end
|
59
|
+
|
55
60
|
it "cannot read corrupted objects" do
|
56
61
|
store.write("a", ["a"*10_000_000]).should == true
|
57
62
|
store.store.write("a_4", nil)
|
@@ -78,6 +83,11 @@ describe LargeObjectStore do
|
|
78
83
|
store.store.keys.should == ["a_0", "a_1", "a_2", "a_3", "a_4", "a_5"]
|
79
84
|
end
|
80
85
|
|
86
|
+
it "uses 1 key when value is small enough" do
|
87
|
+
store.write("a", "a"*500_000)
|
88
|
+
store.store.keys.should == ["a_0"]
|
89
|
+
end
|
90
|
+
|
81
91
|
it "uses read_multi" do
|
82
92
|
store.write("a", "a"*5_000_000)
|
83
93
|
store.store.should_receive(:read).with("a_0").and_return 5
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: large_object_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: acemacu@gmail.com
|