getCachedValue method

dynamic getCachedValue(
  1. String key, {
  2. required dynamic defaultValue,
})

Get a cached value

Implementation

dynamic getCachedValue(String key, {required dynamic defaultValue}) {
  final raw = _cache[key];
  if (raw == null) return null;

  final s = raw.toString();

  if (defaultValue is String) return s;
  if (defaultValue is bool) return s.toLowerCase() == "true";
  if (defaultValue is int) return int.tryParse(s);
  if (defaultValue is double) return double.tryParse(s);

  return null;
}