private async Task <Standard> GetStandard(long standardCode) { try { var standardsView = _inProcessCache.Get <StandardsView>(nameof(StandardsView)); if (standardsView != null) { return(standardsView.Standards?.SingleOrDefault(s => s.Code.Equals(standardCode))); } standardsView = await _apprenticeshipInfoService.GetStandardsAsync(); if (standardsView != null) { _inProcessCache.Set(nameof(StandardsView), standardsView, new TimeSpan(1, 0, 0)); } return(standardsView?.Standards?.SingleOrDefault(s => s.Code.Equals(standardCode))); } catch (Exception e) { _logger.Warn(e, "Could not get standards from apprenticeship API."); } return(null); }
public async Task <StandardsView> GetStandardsAsync(bool refreshCache = false) { if (!_cache.Exists(StandardsKey) || refreshCache) { var response = await _apiClient.Get <GetStandardsResponse>(new GetStandardsRequest()); _cache.Set(StandardsKey, MapFrom(response.Standards)); } return(_cache.Get <StandardsView>(StandardsKey)); }
public Task <StandardsView> GetStandardsAsync(bool refreshCache = false) { if (!_cache.Exists(StandardsKey) || refreshCache) { var api = new StandardApiClient(_apprenticeshipInfoServiceApiBase); //BUG: FindAll should be FindAllAsync - currently a blocking call. var standards = api.FindAll().OrderBy(x => x.Title).ToList(); _cache.Set(StandardsKey, MapFrom(standards)); } return(Task.FromResult(_cache.Get <StandardsView>(StandardsKey))); }
private async Task <List <OrganisationName> > SearchOrganisations(string searchTerm) { var cacheKey = $"SearchKey_{Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(searchTerm))}"; var result = _inProcessCache.Get <List <OrganisationName> >(cacheKey); if (result != null) { return(result); } var processedSearchTerm = CleanSearchTerm(searchTerm); var orgs = await _client.SearchOrganisations(processedSearchTerm); if (orgs == null) { return(new List <OrganisationName>()); } var convertedOrgs = orgs.Select(ConvertToOrganisation).ToList(); result = SortOrganisations(convertedOrgs, processedSearchTerm); _inProcessCache.Set(cacheKey, result, new TimeSpan(0, 15, 0)); return(result); }
public MultiVariantViewLookup GetMultiVariantViews() { var views = _inProcessCache.Get <MultiVariantViewLookup>(nameof(MultiVariantViewLookup)); if (views == null) { views = GetDataFromTableStorage(); if (views.Data != null && views.Data.Any()) { _inProcessCache.Set(nameof(MultiVariantViewLookup), views, new TimeSpan(0, 30, 0)); } } return(views); }
public async Task <Models.ApprenticeshipProvider.Provider> Get(long ukPrn) { var cachedProvider = _inProcessCache.Get <Models.ApprenticeshipProvider.Provider>($"{nameof(Models.ApprenticeshipProvider.Provider)}_{ukPrn}"); if (cachedProvider != null) { return(cachedProvider); } var provider = await _providerService.Get(ukPrn); if (provider != null) { _inProcessCache.Set($"{nameof(Models.ApprenticeshipProvider.Provider)}_{ukPrn}", provider, new DateTimeOffset(DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)))); } return(provider); }
public async Task <DateTime> GetLastEnglishFractionUpdate() { var hmrcLatestUpdateDate = _inProcessCache.Get <DateTime?>("HmrcFractionLastCalculatedDate"); if (hmrcLatestUpdateDate == null) { return(await _executionPolicy.ExecuteAsync(async() => { var accessToken = await GetOgdAccessToken(); hmrcLatestUpdateDate = await _apprenticeshipLevyApiClient.GetLastEnglishFractionUpdate(accessToken); if (hmrcLatestUpdateDate != null) { _inProcessCache.Set("HmrcFractionLastCalculatedDate", hmrcLatestUpdateDate.Value, new TimeSpan(0, 0, 30, 0)); } return hmrcLatestUpdateDate.Value; })); } return(hmrcLatestUpdateDate.Value); }