EventCache constructor

EventCache({
  1. Duration writeToDiskInterval = const Duration(minutes: 5),
})

Implementation

EventCache({
  Duration writeToDiskInterval = const Duration(minutes: 5),
}) {
  // We want to ignore all of these things if we are on web.
  if (!kIsWeb) {
    _read().then((values) {
      _cache.clear();
      _cache.addAll(values);
    });

    Timer.periodic(writeToDiskInterval, (timer) async {
      if (_cache.isEmpty) return;

      // Write the cache to disk
      await _save();
    });
  }
}