getOrCompute<T> static method
T
getOrCompute<T>(})
Get cached value or compute and cache it
Implementation
static T getOrCompute<T>(
String key,
T Function() compute, {
required double width,
required double height,
required String orientation,
}) {
final cacheKey = _generateCacheKey(width, height, orientation);
// Clear cache if device dimensions changed
if (_lastCacheKey != null && _lastCacheKey != cacheKey) {
clear();
}
_lastCacheKey = cacheKey;
final fullKey = '${cacheKey}_$key';
if (_cache.containsKey(fullKey)) {
return _cache[fullKey] as T;
}
final value = compute();
_cache[fullKey] = value;
return value;
}