getOrBuild method

Path getOrBuild(
  1. String key,
  2. Path builder()
)

Returns cached path for key, or builds and caches it via builder.

Implementation

ui.Path getOrBuild(String key, ui.Path Function() builder) {
  if (_cache.containsKey(key)) {
    _hits++;
    final hit = _cache.remove(key)!;
    _cache[key] = hit;
    return hit;
  }
  _misses++;
  if (_cache.length >= _maxSize) {
    _cache.remove(_cache.keys.first);
    _evictions++;
  }
  final path = builder();
  _cache[key] = path;
  return path;
}