Created
August 17, 2017 11:23
-
-
Save jfversluis/6ce2bbf743c4c52b048d3977518f0da1 to your computer and use it in GitHub Desktop.
Retrieving data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void LoadBreaches() | |
{ | |
IsLoading = true; | |
GetBreaches(true); | |
IsLoading = false; | |
} | |
public void GetBreaches(bool force = false) | |
{ | |
var cache = BlobCache.LocalMachine; | |
cache.GetAndFetchLatest("breaches", GetRemoteBreachesAsync, | |
offset => | |
{ | |
TimeSpan elapsed = DateTimeOffset.Now - offset; | |
var invalidateCache = (force || elapsed > new TimeSpan(24, 0, 0)); | |
return invalidateCache; | |
}) | |
.Subscribe((breaches) => | |
{ | |
_breaches.ReplaceRange(breaches); | |
}); | |
} | |
private async Task<IEnumerable<Breach>> GetRemoteBreachesAsync() | |
{ | |
return await _pwnedClient.GetAllBreaches(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment