large_object_store 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/large_object_store/version.rb +1 -1
- data/lib/large_object_store.rb +15 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92be121f082879185822f734dd5fe7935ce04aacb05e900ce4dbfe89b23d712c
|
4
|
+
data.tar.gz: 14854eba125bd1837eb444ec25d65da9ae99228455f600bb4c9cb38902d3ac8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 489ecb7a501deda4f45feb995585999717a595ef6e4539641a6866215d23cf89eb3f745aac02d3b95a4581356405acb21f40f79b010954a3a037cd053172fe5d
|
7
|
+
data.tar.gz: 6c8ad1eead221be4324a5d6557926b8702469797448d68e62a19ded103ad52a0a1dc146599d2f69b1dd6ab5b237659e275d07f9a1542b9aa7a735dc5bb95acf3
|
data/lib/large_object_store.rb
CHANGED
@@ -14,8 +14,11 @@ module LargeObjectStore
|
|
14
14
|
RAW = 2
|
15
15
|
FLAG_RADIX = 32 # we can store 32 different states
|
16
16
|
|
17
|
-
def self.wrap(
|
18
|
-
RailsWrapper.new(
|
17
|
+
def self.wrap(*args)
|
18
|
+
RailsWrapper.new(*args)
|
19
|
+
end
|
20
|
+
class << self
|
21
|
+
ruby2_keywords :wrap if respond_to?(:ruby2_keywords, true)
|
19
22
|
end
|
20
23
|
|
21
24
|
class RailsWrapper
|
@@ -26,9 +29,9 @@ module LargeObjectStore
|
|
26
29
|
@serializer = serializer
|
27
30
|
end
|
28
31
|
|
29
|
-
def write(key, value, options
|
32
|
+
def write(key, value, **options)
|
30
33
|
options = options.dup
|
31
|
-
value = serialize(value, options)
|
34
|
+
value = serialize(value, **options)
|
32
35
|
|
33
36
|
# calculate slice size; note that key length is a factor because
|
34
37
|
# the key is stored on the same slab page as the value
|
@@ -38,11 +41,11 @@ module LargeObjectStore
|
|
38
41
|
pages = (value.size / slice_size.to_f).ceil
|
39
42
|
|
40
43
|
if pages == 1
|
41
|
-
!!@store.write(key(key, 0), value, options)
|
44
|
+
!!@store.write(key(key, 0), value, **options)
|
42
45
|
else
|
43
46
|
# store meta
|
44
47
|
uuid = SecureRandom.hex(UUID_BYTES)
|
45
|
-
return false unless @store.write(key(key, 0), [pages, uuid], options) # invalidates the old cache
|
48
|
+
return false unless @store.write(key(key, 0), [pages, uuid], **options) # invalidates the old cache
|
46
49
|
|
47
50
|
# store object
|
48
51
|
page = 1
|
@@ -50,7 +53,7 @@ module LargeObjectStore
|
|
50
53
|
slice = value.slice!(0, slice_size)
|
51
54
|
break if slice.size == 0
|
52
55
|
|
53
|
-
return false unless @store.write(key(key, page), slice.prepend(uuid),
|
56
|
+
return false unless @store.write(key(key, page), slice.prepend(uuid), raw: true, **options)
|
54
57
|
page += 1
|
55
58
|
end
|
56
59
|
true
|
@@ -84,11 +87,11 @@ module LargeObjectStore
|
|
84
87
|
deserialize(data)
|
85
88
|
end
|
86
89
|
|
87
|
-
def fetch(key, options
|
90
|
+
def fetch(key, **options)
|
88
91
|
value = read(key)
|
89
92
|
return value unless value.nil?
|
90
93
|
value = yield
|
91
|
-
write(key, value, options)
|
94
|
+
write(key, value, **options)
|
92
95
|
value
|
93
96
|
end
|
94
97
|
|
@@ -104,7 +107,7 @@ module LargeObjectStore
|
|
104
107
|
|
105
108
|
# convert a object to a string
|
106
109
|
# modifies options
|
107
|
-
def serialize(value, options)
|
110
|
+
def serialize(value, **options)
|
108
111
|
flag = NORMAL
|
109
112
|
|
110
113
|
if options.delete(:raw)
|
@@ -114,7 +117,7 @@ module LargeObjectStore
|
|
114
117
|
value = @serializer.dump(value)
|
115
118
|
end
|
116
119
|
|
117
|
-
if compress?(value, options)
|
120
|
+
if compress?(value, **options)
|
118
121
|
flag |= COMPRESSED
|
119
122
|
value = Zlib::Deflate.deflate(value)
|
120
123
|
end
|
@@ -132,7 +135,7 @@ module LargeObjectStore
|
|
132
135
|
end
|
133
136
|
|
134
137
|
# Don't pass compression on to Rails, we're doing it ourselves.
|
135
|
-
def compress?(value, options)
|
138
|
+
def compress?(value, **options)
|
136
139
|
return unless options.delete(:compress)
|
137
140
|
compress_limit = options.delete(:compress_limit) || DEFAULT_COMPRESS_LIMIT
|
138
141
|
value.bytesize > compress_limit
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: large_object_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ana Martinez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: acemacu@gmail.com
|
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
rubygems_version: 3.1
|
41
|
+
rubygems_version: 3.0.3.1
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: Store large objects in memcache or others
|