CompactCache class

Ultra-fast single-file cache — hybrid read strategy.

Architecture (inspired by Bitcask + DiskIndex + server BufWriter):

  1. Cold start: loads file into a read-only snapshot (_readBuf)
  2. Reads: zero-copy sublistView from snapshot, RAM buffer, or disk
  3. Writes: buffer in RAM, flush to disk periodically (never blocks UI)
  4. Index: HashMap<String, offset+length> for O(1) lookup

Write buffer: entries accumulate in _pendingBuf (RAM). A periodic timer flushes to disk every 2 seconds if dirty. On read, data is served from the RAM buffer (zero-copy) so reads never wait for flush.

Implemented types

Properties

entryCount → int
no setter
filePath → String
no setter
fileSize → int
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future<void>
evict(String key) → Future<void>
override
flush() → void
Flush dirty data to disk. Call periodically or before close.
get(String key) → Future<Uint8List?>
override
getSync(String key) → Uint8List?
Zero-copy read: snapshot → RAM buffer → disk fallback.
isLocal(String key) → bool
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String key, Uint8List data, {bool isLocal = false}) → Future<void>
override
putAll(Map<String, Uint8List> entries, {bool isLocal = false}) → Future<void>
Batch put — builds one pre-sized buffer, single flush.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

create(String basePath) → Future<CompactCache>