cache_machines 0.1.4-x86_64-linux-musl

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5de5923202ed1cfbf5e7b10f664f3ed736850e8a9f3444c3b9a311f387a551c2
4
+ data.tar.gz: 1293d3d7baca19f73d4657c399d7bc5db652dea41c19275f5c2fd12e201fe276
5
+ SHA512:
6
+ metadata.gz: aa7ae7af9f4de08fb00be5fb261390f66a5af4d98dbd002453eb41a1a6c80f7f603f969929cb8822a3505d594947cb3f658a773357dcd68a61f1fe1d329d7917
7
+ data.tar.gz: 15a9dd3d80bd26916738c9f40f137939a646a171d5fb5bdaa335163114ed1a4f927f83fed19c0a06dafa6ff3f42517b6e4dffab188c89d4a4e9f7b6c03707f05
data/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ ## [0.1.4](https://github.com/seuros/cache_machines/compare/cache_machines/v0.1.3...cache_machines/v0.1.4) (2026-11-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * crates.io keywords and categories for the core ([03e3752](https://github.com/seuros/cache_machines/commit/03e375232563df5cf56b4bbe8435540048b3f2c7))
9
+
10
+ ## [0.1.3](https://github.com/seuros/cache_machines/compare/cache_machines/v0.1.2...cache_machines/v0.1.3) (2026-11-06)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * keep test sources out of the packaged gem and crate ([28635a4](https://github.com/seuros/cache_machines/commit/28635a4df2b2313914957f8cf8b068934bb35f7d))
16
+
17
+ ## [0.1.2](https://github.com/seuros/cache_machines/compare/cache_machines/v0.1.1...cache_machines/v0.1.2) (2026-11-06)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * cross builds no longer compile for the host ([33bc4f3](https://github.com/seuros/cache_machines/commit/33bc4f3fd1ba7bc19bda7930b9d998254d70f923))
23
+
24
+ ## [0.1.1](https://github.com/seuros/cache_machines/compare/cache_machines-v0.1.0...cache_machines/v0.1.1) (2026-11-06)
25
+
26
+
27
+ ### Features
28
+
29
+ * initial extraction ([3569bc6](https://github.com/seuros/cache_machines/commit/3569bc6ccda4ec7c7bc345ab7be84f92e8edcedd))
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdelkader Boudih
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # CacheMachines
2
+
3
+ > Sixty-four berths, and a hatch that asks what you've done to deserve one. 📦
4
+
5
+ An admission-controlled LRU for Ruby. It keeps the most recently used keys in order, names the one it would throw out next, and refuses to throw it out for a newcomer that isn't worth more. You store the payloads and count the hits. It decides what stays.
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ gem 'cache_machines'
11
+ ```
12
+
13
+ ```ruby
14
+ bay = CacheMachines::Lru.new
15
+
16
+ bay.admit(42, candidate_frequency: 1, victim_frequency: 0) # => [:inserted, nil]
17
+ bay.admit(7, candidate_frequency: 1, victim_frequency: 0) # => [:inserted, nil]
18
+ bay.access(42) # => true
19
+ bay.keys # => [42, 7]
20
+ bay.remove(7) # => true
21
+ ```
22
+
23
+ Keys are Integers. Pair them with your own storage, hand the decisions to the bay, and the bay tells you what to keep.
24
+
25
+ ## A Message to the Resistance
26
+
27
+ So you built an LRU cache. Hot rows stay, cold rows fall off the back, dashboards go green. Then the nightly export job runs. It reads every row in the table exactly once, and every one of those reads is a cache miss that inserts a key you will never ask for again.
28
+
29
+ By the time the export finishes, your working set is gone. The 64 keys that got hit ten thousand times each have been shoved out by 64 keys that got hit once. Monday morning is a cold start, and the LRU did exactly what you told it to do.
30
+
31
+ LRU answers "what was used least recently?" It never asks "does the newcomer deserve the slot?" This gem asks. When the bay is full, a candidate has to show up with a higher frequency than the key it would evict. Ties lose. The export job's keys never make it past the hatch.
32
+
33
+ ## Chapter 1: Stardate 2025.186, the AMS Denning
34
+
35
+ > **AMS Denning**, NCC-4203, *Denning*-class cache tender.
36
+ > The hold is finite. The universe of possible consignments is not.
37
+
38
+ The tender has 64 berths and no more. Every consignment that arrives is logged by key, and the manifest is kept in order of last use. When the bay is full and something new arrives, the quartermaster names the berth at the back, asks how often each has been requisitioned, and only swaps if the newcomer wins outright.
39
+
40
+ Somewhere in the fleet, a supply officer proposes:
41
+
42
+ ```ruby
43
+ def fetch(key)
44
+ @cache[key] ||= load(key) # Hash with 64 entries, oldest shifted off
45
+ end
46
+ ```
47
+
48
+ "That," says the quartermaster, "is how one inventory scan empties the bay."
49
+
50
+ ## The Flight Plan
51
+
52
+ What happens to a key offered to `admit`:
53
+
54
+ ```mermaid
55
+ stateDiagram-v2
56
+ [*] --> offered
57
+ offered --> hit: key already aboard, promoted to front
58
+ offered --> inserted: bay has a free berth
59
+ offered --> rejected: bay full, candidate frequency <= victim frequency
60
+ offered --> evicted: bay full, candidate frequency > victim frequency
61
+ evicted --> [*]: victim key returned
62
+ hit --> [*]
63
+ inserted --> [*]
64
+ rejected --> [*]
65
+ ```
66
+
67
+ And the night of the export job:
68
+
69
+ ```mermaid
70
+ sequenceDiagram
71
+ participant App
72
+ participant Bay as Lru (full)
73
+ participant Store as Your storage
74
+
75
+ App->>Bay: victim
76
+ Bay-->>App: 17 (seen 4000 times)
77
+ App->>Bay: admit(export row 9001, candidate 1, victim 4000)
78
+ Bay-->>App: [:rejected, nil]
79
+ Note over App: don't cache the row, serve it and move on
80
+
81
+ App->>Bay: access(17)
82
+ Bay-->>App: true, promoted
83
+
84
+ App->>Bay: victim
85
+ Bay-->>App: 23 (seen 2 times)
86
+ App->>Bay: admit(user 555, candidate 9, victim 2)
87
+ Bay-->>App: [:evicted, 23]
88
+ App->>Store: delete 23, store 555
89
+ ```
90
+
91
+ ## How the Bay Works
92
+
93
+ ### Admit
94
+
95
+ `admit` takes the key, how often the candidate has been requested, and how often the current victim has. It returns a status and, only when something was displaced, the evicted key.
96
+
97
+ ```ruby
98
+ bay = CacheMachines::Lru.new
99
+ bay.admit(1, candidate_frequency: 5, victim_frequency: 0) # => [:inserted, nil]
100
+ bay.admit(1, candidate_frequency: 5, victim_frequency: 0) # => [:hit, nil]
101
+ ```
102
+
103
+ While there's a free berth, frequencies don't matter. The candidate gets in. A key already aboard is a `:hit` and moves to the front.
104
+
105
+ ### When the bay is full
106
+
107
+ Fill all 64 berths and the frequencies start to count.
108
+
109
+ ```ruby
110
+ bay = CacheMachines::Lru.new
111
+ 64.times { |key| bay.admit(key, candidate_frequency: 0, victim_frequency: 0) }
112
+
113
+ bay.victim # => 0
114
+ bay.admit(100, candidate_frequency: 9, victim_frequency: 9) # => [:rejected, nil]
115
+ bay.admit(100, candidate_frequency: 8, victim_frequency: 9) # => [:rejected, nil]
116
+ bay.admit(100, candidate_frequency: 10, victim_frequency: 9) # => [:evicted, 0]
117
+ ```
118
+
119
+ Equal loses. Lower loses. Only strictly higher gets a berth, and then you are told exactly which key just left so you can drop its payload.
120
+
121
+ ### Access
122
+
123
+ A hit promotes the key to the front and returns `true`. A miss returns `false` and inserts nothing. Reading is never admitting.
124
+
125
+ ```ruby
126
+ bay = CacheMachines::Lru.new
127
+ bay.admit(1, candidate_frequency: 0, victim_frequency: 0)
128
+ bay.admit(2, candidate_frequency: 0, victim_frequency: 0)
129
+
130
+ bay.keys # => [2, 1]
131
+ bay.access(1) # => true
132
+ bay.keys # => [1, 2]
133
+ bay.access(9) # => false
134
+ bay.size # => 2
135
+ ```
136
+
137
+ ### Victim
138
+
139
+ `victim` is the key at the back of the line, the one `admit` would evict. It is `nil` until the bay is full. Ask for it right before you admit, look up its frequency, and pass that in.
140
+
141
+ ```ruby
142
+ bay = CacheMachines::Lru.new
143
+ bay.victim # => nil
144
+ 64.times { |key| bay.admit(key, candidate_frequency: 0, victim_frequency: 0) }
145
+ bay.victim # => 0
146
+ bay.access(0)
147
+ bay.victim # => 1
148
+ ```
149
+
150
+ ### Remove and clear
151
+
152
+ ```ruby
153
+ bay = CacheMachines::Lru.new
154
+ bay.admit(1, candidate_frequency: 0, victim_frequency: 0)
155
+ bay.remove(1) # => true
156
+ bay.remove(1) # => false
157
+ bay.clear # => nil
158
+ bay.empty? # => true
159
+ ```
160
+
161
+ `keys` is a snapshot, most recent first. Mutate the array all you like; the bay doesn't notice.
162
+
163
+ ## The Rules of the Tender
164
+
165
+ - **Capacity is 64**, exposed as `CacheMachines::Lru::CAPACITY`. The constructor takes no arguments.
166
+ - **Keys and frequencies are Integers** in `0..2**64-1`. Floats, strings, nil, and objects with `to_int` raise `TypeError`. Negative or too large raises `RangeError`. Bad input is rejected before anything changes.
167
+ - **Both frequencies are keyword arguments** and both are required. Missing or extra keywords raise `ArgumentError`.
168
+ - **Frequencies are yours.** The bay never counts hits. It compares the two numbers you give it and nothing else.
169
+ - **Frozen means frozen.** After `freeze`, every mutator raises `FrozenError`, including a miss on `access` and a `remove` of a key that isn't there.
170
+
171
+ ## What You Think You're Doing vs Reality
172
+
173
+ ### You Think: "A bigger cache would have survived the export."
174
+ ### Reality: Any finite cache loses to a scan larger than itself.
175
+
176
+ The export touches more rows than you have berths. Doubling the bay means it takes twice as long to flush, then flushes anyway. The fix is not more room. The fix is a hatch that asks whether the newcomer has earned a berth, and the answer for a row read once is no.
177
+
178
+ ## What's Yours
179
+
180
+ The bay holds keys and order, nothing else. Payloads live in your store, and when `admit` returns `:evicted` you delete that payload yourself. Frequency counting is yours too, whether that's a counter per key, a sketch, or a column you already have. Treat `victim` then `admit` as one step in your code; the bay won't stop another thread from slipping in between.
181
+
182
+ ## License
183
+
184
+ MIT License. See [LICENSE.txt](LICENSE.txt) for details.
185
+
186
+ **Remember: The export job will read every row once. Make sure once is not enough.**
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## [0.2.2](https://github.com/seuros/cache_machines/compare/cache-machines-v0.2.1...cache-machines-v0.2.2) (2026-11-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * crates.io keywords and categories for the core ([03e3752](https://github.com/seuros/cache_machines/commit/03e375232563df5cf56b4bbe8435540048b3f2c7))
9
+
10
+ ## [0.2.1](https://github.com/seuros/cache_machines/compare/cache-machines-v0.2.0...cache-machines-v0.2.1) (2026-11-06)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * keep test sources out of the packaged gem and crate ([28635a4](https://github.com/seuros/cache_machines/commit/28635a4df2b2313914957f8cf8b068934bb35f7d))
16
+
17
+ ## [0.2.0](https://github.com/seuros/cache_machines/compare/cache-machines-v0.1.0...cache-machines-v0.2.0) (2026-11-06)
18
+
19
+
20
+ ### Features
21
+
22
+ * initial extraction ([3569bc6](https://github.com/seuros/cache_machines/commit/3569bc6ccda4ec7c7bc345ab7be84f92e8edcedd))
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdelkader Boudih
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # cache-machines
2
+
3
+ > **AMS Denning**, NCC-4203, *Denning*-class cache tender.
4
+
5
+ Engine-room flight manual: choose which supplies deserve a berth in limited storage.
6
+
7
+ Allocation-free `no_std` fixed-capacity LRU key policy. Hits move a key to the
8
+ front; accepted new keys evict the least-recently-used key. When full, admission
9
+ requires candidate frequency to exceed the victim's frequency (ties retain the
10
+ incumbent). Frequencies are supplied by the caller, potentially using an existing
11
+ probabilistic sketch; this is not a complete TinyLFU/W-TinyLFU implementation.
12
+
13
+ Values, loading, eviction callbacks, TTLs, byte weights, synchronization, and sketch
14
+ aging are not owned by this policy. Coordinate key-policy mutations with storage
15
+ updates. A zero-capacity cache rejects every insertion.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('ffi/extconf.rb', __dir__)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CacheMachines
4
+ VERSION = '0.1.4'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cache_machines/version'
4
+
5
+ # A missing extension is an installation error. There is no Ruby policy fallback.
6
+ require 'cache_machines_native/cache_machines_native'
@@ -0,0 +1,17 @@
1
+ module CacheMachines
2
+ VERSION: String
3
+
4
+ class Lru
5
+ CAPACITY: Integer
6
+
7
+ def self.new: () -> Lru
8
+ def admit: (Integer key, candidate_frequency: Integer, victim_frequency: Integer) -> [Symbol, Integer?]
9
+ def access: (Integer key) -> bool
10
+ def remove: (Integer key) -> bool
11
+ def clear: () -> nil
12
+ def keys: () -> Array[Integer]
13
+ def size: () -> Integer
14
+ def empty?: () -> bool
15
+ def victim: () -> Integer?
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache_machines
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: x86_64-linux-musl
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A native binding to the allocation-free cache-machines Rust core. Tracks
14
+ numeric keys and caller-measured admission frequencies; payload storage and frequency
15
+ measurement remain with the caller.
16
+ email:
17
+ - oss@seuros.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - CHANGELOG.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - ext/cache_machines_native/core/CHANGELOG.md
26
+ - ext/cache_machines_native/core/LICENSE
27
+ - ext/cache_machines_native/core/README.md
28
+ - ext/cache_machines_native/extconf.rb
29
+ - lib/cache_machines.rb
30
+ - lib/cache_machines/version.rb
31
+ - lib/cache_machines_native/cache_machines_native.so
32
+ - sig/cache_machines.rbs
33
+ homepage: https://github.com/seuros/cache_machines
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ source_code_uri: https://github.com/seuros/cache_machines
38
+ bug_tracker_uri: https://github.com/seuros/cache_machines/issues
39
+ rubygems_mfa_required: 'true'
40
+ cargo_crate_name: cache_machines_native
41
+ cargo_manifest_path: ext/cache_machines_native/ffi/Cargo.toml
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '4.0'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: 4.1.dev
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.3.22
59
+ requirements: []
60
+ rubygems_version: 3.5.23
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Bounded native LRU and admission policy for Ruby
64
+ test_files: []