lutaml-hal 0.2.0 → 0.2.1
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/hal/cache/simple_cache_store.rb +41 -26
- data/lib/lutaml/hal/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: 5860a26a1d8b235f8138e37fe835c3f0de0d4cc065f99b33da9ed17c0cb0a8cf
|
|
4
|
+
data.tar.gz: e558941f569c2d8d55ac62c66924a06a7445438281c261e060471bdf2d8c9f5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3cda001e3ebb066cf62e8aa54fbec2a41ae93a173a056919da2151cf8f28fcba143352ad2dc287d478c7365fa3e087abc1757770264acc05a4be925378072d7
|
|
7
|
+
data.tar.gz: d34fd6af3af5e78d1b223f04fa9f1e9e71ff524b2ac9425935d6bd5e07e4d8fa10a2c255c063c70026388d5f2406a05a41cde1492482cd66a911fb1fe80fb623
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
module Lutaml
|
|
4
4
|
module Hal
|
|
5
5
|
module Cache
|
|
6
|
-
# Simple in-memory cache store for testing and fallback scenarios
|
|
6
|
+
# Simple in-memory cache store for testing and fallback scenarios.
|
|
7
|
+
#
|
|
8
|
+
# Thread-safe: a single mutex guards the cache and its LRU bookkeeping so
|
|
9
|
+
# it can back the register cache when consumers realize links from many
|
|
10
|
+
# threads (e.g. a parallel fetcher).
|
|
7
11
|
class SimpleCacheStore
|
|
8
12
|
attr_reader :max_size
|
|
9
13
|
|
|
@@ -11,52 +15,63 @@ module Lutaml
|
|
|
11
15
|
@max_size = max_size
|
|
12
16
|
@cache = {}
|
|
13
17
|
@access_order = []
|
|
18
|
+
@mutex = Mutex.new
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
def get(key)
|
|
17
|
-
|
|
22
|
+
@mutex.synchronize do
|
|
23
|
+
return nil unless @cache.key?(key)
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
# Update access order for LRU
|
|
26
|
+
@access_order.delete(key)
|
|
27
|
+
@access_order.push(key)
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
@cache[key]
|
|
30
|
+
end
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
def set(key, value)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
@mutex.synchronize do
|
|
35
|
+
# Remove existing entry if present
|
|
36
|
+
if @cache.key?(key)
|
|
37
|
+
@access_order.delete(key)
|
|
38
|
+
elsif @cache.size >= @max_size
|
|
39
|
+
# Evict least recently used item
|
|
40
|
+
lru_key = @access_order.shift
|
|
41
|
+
@cache.delete(lru_key)
|
|
42
|
+
end
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
@cache[key] = value
|
|
45
|
+
@access_order.push(key)
|
|
46
|
+
end
|
|
38
47
|
end
|
|
39
48
|
|
|
40
49
|
def delete(key)
|
|
41
|
-
@
|
|
42
|
-
|
|
50
|
+
@mutex.synchronize do
|
|
51
|
+
@access_order.delete(key)
|
|
52
|
+
@cache.delete(key)
|
|
53
|
+
end
|
|
43
54
|
end
|
|
44
55
|
|
|
45
56
|
def clear
|
|
46
|
-
@
|
|
47
|
-
|
|
57
|
+
@mutex.synchronize do
|
|
58
|
+
@cache.clear
|
|
59
|
+
@access_order.clear
|
|
60
|
+
end
|
|
48
61
|
end
|
|
49
62
|
|
|
50
63
|
def size
|
|
51
|
-
@cache.size
|
|
64
|
+
@mutex.synchronize { @cache.size }
|
|
52
65
|
end
|
|
53
66
|
|
|
54
67
|
def stats
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
@mutex.synchronize do
|
|
69
|
+
{
|
|
70
|
+
size: @cache.size,
|
|
71
|
+
max_size: @max_size,
|
|
72
|
+
keys: @cache.keys
|
|
73
|
+
}
|
|
74
|
+
end
|
|
60
75
|
end
|
|
61
76
|
|
|
62
77
|
def cache_info
|
data/lib/lutaml/hal/version.rb
CHANGED