read static method

dynamic read(
  1. String key
)

Returns cached data for key or null on miss/expiry.

Implementation

static dynamic read(String key) {
  // L1
  final mem = _memory[key];
  if (mem != null) {
    if (!mem.isExpired) return mem.data;
    _memory.remove(key); // evict expired
  }

  // L2
  final raw = _box?.get(key);
  if (raw != null) {
    final entry = _HiveEntry.fromMap(raw as Map);
    if (!entry.isExpired) {
      // Warm L1 from L2
      _memory[key] = _MemoryEntry(
          data: entry.data,
          expiresAt: DateTime.fromMillisecondsSinceEpoch(entry.expiresAtMs));
      return entry.data;
    }
    _box?.delete(key); // evict expired from Hive
  }

  return null;
}