large_object_store 1.3.4 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Readme.md +1 -1
- data/lib/large_object_store/version.rb +1 -1
- data/lib/large_object_store.rb +19 -15
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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/Readme.md
CHANGED
@@ -33,4 +33,4 @@ acemacu@gmail.com<br/>
|
|
33
33
|
[Michael Grosser](https://github.com/grosser)<br/>
|
34
34
|
michael@grosser.it<br/>
|
35
35
|
License: MIT<br/>
|
36
|
-
[![
|
36
|
+
[![CI](https://github.com/anamartinez/large_object_store/actions/workflows/actions.yml/badge.svg)](https://github.com/anamartinez/large_object_store/actions/workflows/actions.yml)
|
data/lib/large_object_store.rb
CHANGED
@@ -14,20 +14,24 @@ 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
|
22
25
|
attr_reader :store
|
23
26
|
|
24
|
-
def initialize(store)
|
27
|
+
def initialize(store, serializer: Marshal)
|
25
28
|
@store = store
|
29
|
+
@serializer = serializer
|
26
30
|
end
|
27
31
|
|
28
|
-
def write(key, value, options
|
32
|
+
def write(key, value, **options)
|
29
33
|
options = options.dup
|
30
|
-
value = serialize(value, options)
|
34
|
+
value = serialize(value, **options)
|
31
35
|
|
32
36
|
# calculate slice size; note that key length is a factor because
|
33
37
|
# the key is stored on the same slab page as the value
|
@@ -37,11 +41,11 @@ module LargeObjectStore
|
|
37
41
|
pages = (value.size / slice_size.to_f).ceil
|
38
42
|
|
39
43
|
if pages == 1
|
40
|
-
!!@store.write(key(key, 0), value, options)
|
44
|
+
!!@store.write(key(key, 0), value, **options)
|
41
45
|
else
|
42
46
|
# store meta
|
43
47
|
uuid = SecureRandom.hex(UUID_BYTES)
|
44
|
-
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
|
45
49
|
|
46
50
|
# store object
|
47
51
|
page = 1
|
@@ -49,7 +53,7 @@ module LargeObjectStore
|
|
49
53
|
slice = value.slice!(0, slice_size)
|
50
54
|
break if slice.size == 0
|
51
55
|
|
52
|
-
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)
|
53
57
|
page += 1
|
54
58
|
end
|
55
59
|
true
|
@@ -83,11 +87,11 @@ module LargeObjectStore
|
|
83
87
|
deserialize(data)
|
84
88
|
end
|
85
89
|
|
86
|
-
def fetch(key, options
|
90
|
+
def fetch(key, **options)
|
87
91
|
value = read(key)
|
88
92
|
return value unless value.nil?
|
89
93
|
value = yield
|
90
|
-
write(key, value, options)
|
94
|
+
write(key, value, **options)
|
91
95
|
value
|
92
96
|
end
|
93
97
|
|
@@ -103,17 +107,17 @@ module LargeObjectStore
|
|
103
107
|
|
104
108
|
# convert a object to a string
|
105
109
|
# modifies options
|
106
|
-
def serialize(value, options)
|
110
|
+
def serialize(value, **options)
|
107
111
|
flag = NORMAL
|
108
112
|
|
109
113
|
if options.delete(:raw)
|
110
114
|
flag |= RAW
|
111
115
|
value = value.to_s
|
112
116
|
else
|
113
|
-
value =
|
117
|
+
value = @serializer.dump(value)
|
114
118
|
end
|
115
119
|
|
116
|
-
if compress?(value, options)
|
120
|
+
if compress?(value, **options)
|
117
121
|
flag |= COMPRESSED
|
118
122
|
value = Zlib::Deflate.deflate(value)
|
119
123
|
end
|
@@ -126,12 +130,12 @@ module LargeObjectStore
|
|
126
130
|
data = raw_data.dup
|
127
131
|
flag = data.slice!(0, 1).to_i(FLAG_RADIX)
|
128
132
|
data = Zlib::Inflate.inflate(data) if flag & COMPRESSED == COMPRESSED
|
129
|
-
data =
|
133
|
+
data = @serializer.load(data) if flag & RAW != RAW
|
130
134
|
data
|
131
135
|
end
|
132
136
|
|
133
137
|
# Don't pass compression on to Rails, we're doing it ourselves.
|
134
|
-
def compress?(value, options)
|
138
|
+
def compress?(value, **options)
|
135
139
|
return unless options.delete(:compress)
|
136
140
|
compress_limit = options.delete(:compress_limit) || DEFAULT_COMPRESS_LIMIT
|
137
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
|
@@ -31,15 +31,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '2.
|
34
|
+
version: '2.5'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
|
42
|
-
rubygems_version: 2.6.14
|
41
|
+
rubygems_version: 3.0.3.1
|
43
42
|
signing_key:
|
44
43
|
specification_version: 4
|
45
44
|
summary: Store large objects in memcache or others
|