Class: RailsAiBridge::Fingerprinter::CachedSnapshot
- Inherits:
-
Object
- Object
- RailsAiBridge::Fingerprinter::CachedSnapshot
- Defined in:
- lib/rails_ai_bridge/fingerprinter/cached_snapshot.rb
Overview
Caches fingerprint snapshots to avoid redundant filesystem walks.
Every +ContextProvider.fetch+ triggers a +Fingerprinter.snapshot+ call that walks 10+ directories reading mtimes. This class caches the result for a short TTL (default 5s), so rapid MCP tool calls reuse the same snapshot without repeated I/O.
Thread-safe via +Mutex+.
Class Attribute Summary collapse
-
.snapshot_ttl ⇒ Integer
Seconds to cache a fingerprint snapshot.
Class Method Summary collapse
-
.fetch(app) ⇒ String
Returns the fingerprint for +app+, reusing a cached value when the snapshot TTL has not expired.
-
.invalidate!(app) ⇒ void
Invalidates the cached snapshot for a specific app, forcing re-computation on the next +fetch+.
-
.reset! ⇒ void
Clears all cached snapshots.
Class Attribute Details
.snapshot_ttl ⇒ Integer
Returns seconds to cache a fingerprint snapshot.
20 21 22 |
# File 'lib/rails_ai_bridge/fingerprinter/cached_snapshot.rb', line 20 def snapshot_ttl @snapshot_ttl end |
Class Method Details
.fetch(app) ⇒ String
Returns the fingerprint for +app+, reusing a cached value when the snapshot TTL has not expired.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_ai_bridge/fingerprinter/cached_snapshot.rb', line 27 def fetch(app) @mutex.synchronize do key = app.object_id entry = @cache[key] if entry && ttl_valid?(entry) entry[:fingerprint] else compute_and_cache(app, key) end end end |
.invalidate!(app) ⇒ void
This method returns an undefined value.
Invalidates the cached snapshot for a specific app, forcing re-computation on the next +fetch+.
52 53 54 |
# File 'lib/rails_ai_bridge/fingerprinter/cached_snapshot.rb', line 52 def invalidate!(app) @mutex.synchronize { @cache.delete(app.object_id) } end |
.reset! ⇒ void
This method returns an undefined value.
Clears all cached snapshots.
43 44 45 |
# File 'lib/rails_ai_bridge/fingerprinter/cached_snapshot.rb', line 43 def reset! @mutex.synchronize { @cache.clear } end |