canon 0.3.68 → 0.3.69
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/canon/cache.rb +25 -16
- data/lib/canon/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: 4f23fa758538acdbe352d58250d880b04e905191ce3c44b30528580cee06f224
|
|
4
|
+
data.tar.gz: c33b27f2839764f6d91fded3b3d7cb2042dc7e91d1d7a630037bcda0ce645c37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6137233af91995ea5956d35fa154d2c206557e30c7fd9d1ced455667560f05810a034c4a1c407e4635fdbaefe8ad9929ad5b28cdf4cf5118990d83865611c4a3
|
|
7
|
+
data.tar.gz: 16a631574442c56fc87e5a48851643630ba9342d7e06f4b0b938f28a24792d5b414884099ec7c767fedb067971cc6ab82cf48871d55a1d1551f9cc5d7886e868
|
data/lib/canon/cache.rb
CHANGED
|
@@ -24,7 +24,14 @@ module Canon
|
|
|
24
24
|
# Maximum number of entries per cache category
|
|
25
25
|
MAX_CACHE_SIZE = 100
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
LOCK = Mutex.new
|
|
28
|
+
|
|
29
|
+
# Fetch a value from cache, or compute and cache it.
|
|
30
|
+
#
|
|
31
|
+
# The lock covers the cache operations only — never the compute
|
|
32
|
+
# block — so concurrent parses stay parallel; duplicate computes
|
|
33
|
+
# for the same key may race (last write wins), which any
|
|
34
|
+
# check-then-compute cache accepts.
|
|
28
35
|
#
|
|
29
36
|
# @param category [Symbol] Cache category (:document_parse, :format_detect, etc.)
|
|
30
37
|
# @param key [String] Cache key
|
|
@@ -33,24 +40,24 @@ module Canon
|
|
|
33
40
|
def fetch(category, key)
|
|
34
41
|
cache = cache_for(category)
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
LOCK.synchronize do
|
|
44
|
+
if cache.key?(key)
|
|
45
|
+
@clock = (@clock || 0) + 1
|
|
46
|
+
cache[key][:accessed] = @clock
|
|
47
|
+
return cache[key][:value]
|
|
48
|
+
end
|
|
41
49
|
end
|
|
42
50
|
|
|
43
|
-
# Compute and cache the value
|
|
44
51
|
value = yield
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
LOCK.synchronize do
|
|
54
|
+
if cache.size >= MAX_CACHE_SIZE
|
|
55
|
+
oldest_key = cache.min_by { |_, v| v[:accessed] }&.first
|
|
56
|
+
cache.delete(oldest_key) if oldest_key
|
|
57
|
+
end
|
|
58
|
+
@clock = (@clock || 0) + 1
|
|
59
|
+
cache[key] = { value: value, accessed: @clock }
|
|
50
60
|
end
|
|
51
|
-
|
|
52
|
-
@clock = (@clock || 0) + 1
|
|
53
|
-
cache[key] = { value: value, accessed: @clock }
|
|
54
61
|
value
|
|
55
62
|
end
|
|
56
63
|
|
|
@@ -58,8 +65,10 @@ module Canon
|
|
|
58
65
|
#
|
|
59
66
|
# Useful for tests or when memory needs to be freed
|
|
60
67
|
def clear_all
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
LOCK.synchronize do
|
|
69
|
+
@caches&.each_value(&:clear)
|
|
70
|
+
@caches = nil
|
|
71
|
+
end
|
|
63
72
|
end
|
|
64
73
|
|
|
65
74
|
# Clear a specific cache category
|
data/lib/canon/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: canon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.69
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: diff-lcs
|