Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created August 17, 2017 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/6ce2bbf743c4c52b048d3977518f0da1 to your computer and use it in GitHub Desktop.
Save jfversluis/6ce2bbf743c4c52b048d3977518f0da1 to your computer and use it in GitHub Desktop.
Retrieving data
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