Class: RailVerdict::MCP::Cache
- Inherits:
-
Object
- Object
- RailVerdict::MCP::Cache
- Defined in:
- lib/rail_verdict/mcp/cache.rb
Constant Summary collapse
- MAX_STATUS_BYTES =
1 * 1024 * 1024
- MAX_DIRTY_FILES =
500- MAX_STATE_FILE_BYTES =
2 * 1024 * 1024
Instance Method Summary collapse
- #fetch_outcome ⇒ Object
- #fetch_packet(packet_id) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #stale? ⇒ Boolean
- #store_outcome(outcome) ⇒ Object
- #store_packet(packet_hash) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
13 14 15 16 17 18 |
# File 'lib/rail_verdict/mcp/cache.rb', line 13 def initialize @mutex = Mutex.new @last_outcome = nil @last_digests = nil @last_packets = {} end |
Instance Method Details
#fetch_outcome ⇒ Object
27 28 29 |
# File 'lib/rail_verdict/mcp/cache.rb', line 27 def fetch_outcome @mutex.synchronize { @last_outcome } end |
#fetch_packet(packet_id) ⇒ Object
49 50 51 |
# File 'lib/rail_verdict/mcp/cache.rb', line 49 def fetch_packet(packet_id) @mutex.synchronize { @last_packets[packet_id] } end |
#stale? ⇒ Boolean
35 36 37 |
# File 'lib/rail_verdict/mcp/cache.rb', line 35 def stale? !valid? end |
#store_outcome(outcome) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/rail_verdict/mcp/cache.rb', line 20 def store_outcome(outcome) @mutex.synchronize do @last_outcome = outcome @last_digests = digests_for(outcome) end end |
#store_packet(packet_hash) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rail_verdict/mcp/cache.rb', line 39 def store_packet(packet_hash) @mutex.synchronize do @last_packets[packet_hash["packet_id"]] = packet_hash if @last_packets.size > 10 oldest = @last_packets.keys.first @last_packets.delete(oldest) end end end |
#valid? ⇒ Boolean
31 32 33 |
# File 'lib/rail_verdict/mcp/cache.rb', line 31 def valid? @mutex.synchronize { valid_unsynchronized? } end |