lutaml-store 0.3.1 → 0.3.2
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/adapter/memory.rb +17 -0
- data/lib/lutaml/store/config.rb +2 -1
- data/lib/lutaml/store/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3666640ef12a937789e1fa2357edbb7bb882468a78fac8053e8bcc0efbe94ccd
|
|
4
|
+
data.tar.gz: da2a66ff3067ead5082ff16a6abea51232e49359a63b84e4cde45a3e42c768ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d8eba2c1775fc8ac1fd170c4134be61046954212319ba63e5d6ca8ffeca845a5e3a808e49fded3668f6dba387d7f75b326a6b7821e17375f658a4ad76c92b75
|
|
7
|
+
data.tar.gz: 75f6f23cbfd0f30cc58a7d21f45906878d260f07bf4b2201b84ca75493233d79406c71df1692353a7e263df962f5a34e498007ecc11c7a0ed46c2ffa89db4c97
|
|
@@ -18,6 +18,7 @@ module Lutaml
|
|
|
18
18
|
@ttl_enabled = @config.fetch(:ttl_enabled, false)
|
|
19
19
|
@ttl_data = @ttl_enabled ? {} : nil
|
|
20
20
|
@default_ttl = @config[:default_ttl] || 3600
|
|
21
|
+
@max_entries = @config[:max_entries]
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
# ── Read operations (lock-free via snapshot) ──
|
|
@@ -64,6 +65,7 @@ module Lutaml
|
|
|
64
65
|
|
|
65
66
|
def set(key, value, metadata = {})
|
|
66
67
|
@write_mutex.synchronize do
|
|
68
|
+
evict_oldest_if_needed(key)
|
|
67
69
|
@data[key] = value
|
|
68
70
|
invalidate_snapshot
|
|
69
71
|
|
|
@@ -118,6 +120,7 @@ module Lutaml
|
|
|
118
120
|
def bulk_set(key_value_pairs, ttl: nil)
|
|
119
121
|
@write_mutex.synchronize do
|
|
120
122
|
key_value_pairs.each do |key, value|
|
|
123
|
+
evict_oldest_if_needed(key)
|
|
121
124
|
@data[key] = value
|
|
122
125
|
|
|
123
126
|
if @ttl_enabled
|
|
@@ -255,6 +258,7 @@ module Lutaml
|
|
|
255
258
|
snap = snapshot
|
|
256
259
|
super.merge(
|
|
257
260
|
size: snap.size,
|
|
261
|
+
max_entries: @max_entries,
|
|
258
262
|
ttl_enabled: @ttl_enabled,
|
|
259
263
|
expired_keys: @ttl_enabled ? count_expired_keys : 0
|
|
260
264
|
)
|
|
@@ -279,6 +283,19 @@ module Lutaml
|
|
|
279
283
|
@snapshot_stale = true
|
|
280
284
|
end
|
|
281
285
|
|
|
286
|
+
# Capacity bound (max_entries): evict the oldest-INSERTED entry to
|
|
287
|
+
# make room. Insertion order, not access order — refreshing on read
|
|
288
|
+
# would cost the lock-free snapshot reads. Updating an existing key
|
|
289
|
+
# never evicts.
|
|
290
|
+
def evict_oldest_if_needed(incoming_key)
|
|
291
|
+
return if @max_entries.nil? || @data.key?(incoming_key) ||
|
|
292
|
+
@data.size < @max_entries
|
|
293
|
+
|
|
294
|
+
oldest = @data.each_key.first
|
|
295
|
+
@data.delete(oldest)
|
|
296
|
+
@ttl_data&.delete(oldest)
|
|
297
|
+
end
|
|
298
|
+
|
|
282
299
|
def cleanup_expired_if_needed
|
|
283
300
|
return unless @ttl_enabled
|
|
284
301
|
|
data/lib/lutaml/store/config.rb
CHANGED
|
@@ -12,7 +12,8 @@ module Lutaml
|
|
|
12
12
|
|
|
13
13
|
def initialize(adapter_type: :memory, adapter_options: {},
|
|
14
14
|
cache: {}, monitoring: {}, events: {},
|
|
15
|
-
compression: {}, serialization: {}, **)
|
|
15
|
+
compression: {}, serialization: {}, adapter: nil, **)
|
|
16
|
+
adapter_type = adapter if adapter.is_a?(Hash)
|
|
16
17
|
@adapter_type = normalize_adapter_type(adapter_type)
|
|
17
18
|
@adapter_options = inline_adapter_options(adapter_type).merge(symbolize_keys(adapter_options))
|
|
18
19
|
|
data/lib/lutaml/store/version.rb
CHANGED