probe static method

SystemMemoryInfo? probe({
  1. Duration maxAge = const Duration(seconds: 5),
})

Reads current system memory, or null if unavailable on this platform/right now (see the class doc comment). Shelling out on every call would be wasteful for a caller probing repeatedly in a short window, so a reading is reused for maxAge before this shells out again; pass Duration.zero to force a fresh read.

Implementation

static SystemMemoryInfo? probe({
  Duration maxAge = const Duration(seconds: 5),
}) {
  final cached = _cached;
  final cachedAt = _cachedAt;
  if (cached != null &&
      cachedAt != null &&
      DateTime.now().difference(cachedAt) < maxAge) {
    return cached;
  }
  final fresh = _probeUncached();
  if (fresh != null) {
    _cached = fresh;
    _cachedAt = DateTime.now();
  }
  return fresh;
}