saveRemember<T> method
Saves a value in the cache with an expiration time.
Implementation
Future<T> saveRemember<T>(
String key,
int seconds,
Function() callback,
) async {
if (_store.containsKey(key)) {
final entry = _store[key]!;
if (entry.expiration == null ||
NyTime.now().isBefore(entry.expiration!)) {
return entry.value as T;
}
}
T value;
if (callback is Future Function()) {
value = await callback() as T;
} else {
value = callback() as T;
}
final expiration = NyTime.now().add(Duration(seconds: seconds));
_store[key] = _CacheEntry(value: value, expiration: expiration);
return value;
}