Class: X402::BSV::TxidStore::Memory
- Inherits:
-
Object
- Object
- X402::BSV::TxidStore::Memory
- Defined in:
- lib/x402/bsv/txid_store.rb
Overview
In-memory backend suitable for development and single-process deployments. Thread-safe via Monitor. Entries expire after +ttl+ seconds.
NOTE: This store provides no deduplication across OS processes. Production multi-process deployments should use a shared backend.
Constant Summary collapse
- DEFAULT_TTL =
600- DEFAULT_MAX_SIZE =
10_000
Instance Method Summary collapse
-
#initialize(ttl: DEFAULT_TTL, max_size: DEFAULT_MAX_SIZE) ⇒ Memory
constructor
A new instance of Memory.
-
#record_if_unseen!(txid) ⇒ Object
Atomically checks and records a txid.
Constructor Details
#initialize(ttl: DEFAULT_TTL, max_size: DEFAULT_MAX_SIZE) ⇒ Memory
Returns a new instance of Memory.
25 26 27 28 29 30 |
# File 'lib/x402/bsv/txid_store.rb', line 25 def initialize(ttl: DEFAULT_TTL, max_size: DEFAULT_MAX_SIZE) @entries = {} @monitor = Monitor.new @ttl = ttl @max_size = max_size end |
Instance Method Details
#record_if_unseen!(txid) ⇒ Object
Atomically checks and records a txid. Returns true if the txid was new (now recorded). Returns false if already seen (duplicate).
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/x402/bsv/txid_store.rb', line 35 def record_if_unseen!(txid) @monitor.synchronize do purge_expired! entry = @entries[txid] return false if entry && !expired?(entry) @entries[txid] = monotonic_now evict_oldest! if @entries.size > @max_size true end end |