Skip to content

Commit

Permalink
Fetch format data for songs for a specific artist and cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
czf committed Apr 18, 2021
1 parent 8834f6a commit 951f47f
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace RadiocomDataViewApp.Clients.Live
public class LiveRadiocomArtistWorkRepository : IRadiocomArtistWorkRepository
{
private const string LOCALSTORAGEKEY_ARTISTWORK_INFO = "artistwork_info-";
private const string LOCALSTORAGEKEY_ARTISTARTISTWORK_INFO = "artistartistwork_info-";
private readonly IRadiocomArtistRepository _radiocomArtistRepository;
private readonly HttpClient _httpClient;
private readonly ILocalStorageService _localStorageService;
Expand Down Expand Up @@ -83,9 +84,28 @@ public async Task<IEnumerable<ArtistWorkInfo>> GetArtistWorksAsync()
return result;
}

public Task<IEnumerable<ArtistWorkInfo>> GetArtist_ArtistWorks(int artistId)
public async Task<IEnumerable<ArtistWorkInfo>> GetArtist_ArtistWorks(int artistId)
{
throw new NotImplementedException();
List<ArtistWorkInfo> result;
string localStorageKey = LOCALSTORAGEKEY_ARTISTARTISTWORK_INFO + "all";
TimeCachedObject<List<ArtistWorkInfo>> cachedObject = await _localStorageService.GetItemAsync<TimeCachedObject<List<ArtistWorkInfo>>>(localStorageKey);
if (cachedObject == null || cachedObject.NextUpdateHour < DateTimeOffset.UtcNow)
{
result = (await GetArtistWorksAsync()).Where(x => x.ArtistInfo.Id == artistId).ToList();
DateTimeOffset nextUpdate = TimeCachedObject<object>.CalculateNextUpdateHour();
cachedObject = new TimeCachedObject<List<ArtistWorkInfo>>()
{
CachedObject = result,
NextUpdateHour = nextUpdate
};
await _localStorageService.SetItemAsync(localStorageKey, cachedObject);
}
else
{
result = cachedObject.CachedObject;
}

return result;
}

private class ArtistWorkInfosRequest
Expand Down

0 comments on commit 951f47f

Please sign in to comment.