getOrPutFor static method

double getOrPutFor(
  1. DimenMetrics metrics,
  2. CacheKey key,
  3. double compute()
)

Resolves key against an explicit coherent metrics snapshot.

Implementation

static double getOrPutFor(
  DimenMetrics metrics,
  CacheKey key,
  double Function() compute,
) {
  if (!_enabled || key.hasCustomSensitivity || shouldBypassCache(key)) {
    return compute();
  }
  final cache = _cacheFor(metrics);
  final hit = cache.entries[key];
  if (hit != null) {
    _hits++;
    return hit;
  }
  _misses++;
  final value = compute();
  if (value.isFinite) cache.insert(key, value);
  return value;
}