Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2018 13:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wiredprairie/dde9e1dde91fc35de9f1d42e37903cf7 to your computer and use it in GitHub Desktop.
Future<File> _getCacheFile() async {
final dir = (await getApplicationDocumentsDirectory()).path;
return new File('$dir/hotlist.xml');
Future<XmlDocument> _getHotListCache() async {
try {
final file = await _getCacheFile();
return parse(await file.readAsString());
on FileSystemException {
return _getDefaultHotGameInfo();
Future<bool> _hotListCacheFileExists() async =>
await (await _getCacheFile()).exists();
Future<Null> _saveHotListToCache(XmlDocument doc) async {
try {
final file = await _getCacheFile();
final sink = await file.openWrite();
await sink.write(doc.toXmlString(pretty: true));
await sink.close();
final prefs = await SharedPreferences.getInstance();
final later = new Duration(hours: 8));
prefs.setInt(NEXT_CACHE_UPDATE_EPOCH_KEY, later.millisecondsSinceEpoch);
setState(() {
_nextUpdate = new DateTime.fromMicrosecondsSinceEpoch(
later.millisecondsSinceEpoch * 1000);
_lastUpdate = new;
await prefs.commit();
catch (exception) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment