lutaml-store 0.3.4 → 0.3.6
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.
- checksums.yaml +4 -4
- data/lib/lutaml/store/cache.rb +20 -18
- data/lib/lutaml/store/config.rb +2 -0
- data/lib/lutaml/store/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e42310e03af535e02154a3187b7095bcaf19bd1c5071d77325f17362c50d78e9
|
|
4
|
+
data.tar.gz: e946e44cfd38705e5b0ed0f8f2b8966a9380bdb30e098c35061bc4f83165d2b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 769fe8c2230455cf50ed053d9034a2ef89cbaf80c7b1f800f78bf04493a9b05caddfbac1d3b9d355f1253b2aebf71e4cc27414e82ea80092fabd2d127b3a75fe
|
|
7
|
+
data.tar.gz: 60bb8a50abceb70098dc672b5e66aa98042674da27d887b6eacbffca68e7cbbec396f3e0d0b50fb985484d927b141e8ff36a2c07dc58ce96e87722e4dabf3eaa
|
data/lib/lutaml/store/cache.rb
CHANGED
|
@@ -7,11 +7,15 @@ module Lutaml
|
|
|
7
7
|
|
|
8
8
|
DEFAULT_MAX_SIZE = 1000
|
|
9
9
|
|
|
10
|
+
# LRU over Hash insertion order: re-inserting a key moves it to the
|
|
11
|
+
# newest position, so the first entry is always the least recently
|
|
12
|
+
# used. Ruby Hashes are ordered, which keeps every operation O(1);
|
|
13
|
+
# the previous access-order Array re-scanned on every hit (O(n),
|
|
14
|
+
# ~40us per hit at 1000 entries, all under the lock).
|
|
10
15
|
def initialize(max_size: DEFAULT_MAX_SIZE, ttl: nil)
|
|
11
16
|
@max_size = max_size
|
|
12
17
|
@ttl = ttl
|
|
13
18
|
@data = {}
|
|
14
|
-
@access_order = []
|
|
15
19
|
@mutex = Mutex.new
|
|
16
20
|
end
|
|
17
21
|
|
|
@@ -21,18 +25,15 @@ module Lutaml
|
|
|
21
25
|
return nil unless entry
|
|
22
26
|
return nil if expired?(entry)
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
@access_order << key
|
|
28
|
+
refresh_recency(key, entry)
|
|
26
29
|
entry.value
|
|
27
30
|
end
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
def set(key, value)
|
|
31
34
|
@mutex.synchronize do
|
|
32
|
-
@
|
|
33
|
-
|
|
35
|
+
@data.delete(key)
|
|
34
36
|
@data[key] = Entry.new(value: value, timestamp: Time.now)
|
|
35
|
-
@access_order << key
|
|
36
37
|
|
|
37
38
|
evict_lru while @data.size > @max_size
|
|
38
39
|
end
|
|
@@ -40,26 +41,23 @@ module Lutaml
|
|
|
40
41
|
|
|
41
42
|
def delete(key)
|
|
42
43
|
@mutex.synchronize do
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
true
|
|
46
|
-
else
|
|
47
|
-
false
|
|
48
|
-
end
|
|
44
|
+
entry = @data.delete(key)
|
|
45
|
+
entry ? true : false
|
|
49
46
|
end
|
|
50
47
|
end
|
|
51
48
|
|
|
52
49
|
def exists?(key)
|
|
53
50
|
@mutex.synchronize do
|
|
54
51
|
entry = @data[key]
|
|
55
|
-
|
|
52
|
+
return false unless entry
|
|
53
|
+
|
|
54
|
+
!expired?(entry)
|
|
56
55
|
end
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
def clear
|
|
60
59
|
@mutex.synchronize do
|
|
61
60
|
@data.clear
|
|
62
|
-
@access_order.clear
|
|
63
61
|
end
|
|
64
62
|
end
|
|
65
63
|
|
|
@@ -83,7 +81,6 @@ module Lutaml
|
|
|
83
81
|
expired_keys = @data.select { |_, entry| expired?(entry) }.keys
|
|
84
82
|
expired_keys.each do |key|
|
|
85
83
|
@data.delete(key)
|
|
86
|
-
@access_order.delete(key)
|
|
87
84
|
end
|
|
88
85
|
expired_keys.size
|
|
89
86
|
end
|
|
@@ -91,6 +88,11 @@ module Lutaml
|
|
|
91
88
|
|
|
92
89
|
private
|
|
93
90
|
|
|
91
|
+
def refresh_recency(key, entry)
|
|
92
|
+
@data.delete(key)
|
|
93
|
+
@data[key] = entry
|
|
94
|
+
end
|
|
95
|
+
|
|
94
96
|
def expired?(entry)
|
|
95
97
|
return false unless @ttl
|
|
96
98
|
|
|
@@ -98,10 +100,10 @@ module Lutaml
|
|
|
98
100
|
end
|
|
99
101
|
|
|
100
102
|
def evict_lru
|
|
101
|
-
return if @
|
|
103
|
+
return if @data.empty?
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
@data.delete(
|
|
105
|
+
oldest_key = @data.each_key.first
|
|
106
|
+
@data.delete(oldest_key)
|
|
105
107
|
end
|
|
106
108
|
end
|
|
107
109
|
end
|
data/lib/lutaml/store/config.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Lutaml
|
|
|
10
10
|
:compression_algorithm, :compression_level, :serialization_formats,
|
|
11
11
|
:validate_on_write
|
|
12
12
|
|
|
13
|
+
# rubocop:disable Metrics/ParameterLists
|
|
13
14
|
def initialize(adapter_type: :memory, adapter_options: {},
|
|
14
15
|
cache: {}, monitoring: {}, events: {},
|
|
15
16
|
compression: {}, serialization: {}, adapter: nil, **)
|
|
@@ -37,6 +38,7 @@ module Lutaml
|
|
|
37
38
|
@serialization_formats = serialization_config.fetch(:formats, %w[marshal hash json yaml xml toml])
|
|
38
39
|
@validate_on_write = serialization_config.fetch(:validate_on_write, false)
|
|
39
40
|
end
|
|
41
|
+
# rubocop:enable Metrics/ParameterLists
|
|
40
42
|
|
|
41
43
|
def self.from_file(file_path)
|
|
42
44
|
config_data = YAML.load_file(file_path)
|
data/lib/lutaml/store/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-store
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ronald Tse
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|