private async Task <List <ApprenticeshipModel> > GetApprenticeships(string key) { var apprenticeshipsCacheValue = await dataCache.TryGet(key.ToString()).ConfigureAwait(false); var apprenticeships = apprenticeshipsCacheValue.HasValue ? apprenticeshipsCacheValue.Value : new List <ApprenticeshipModel>(); return(apprenticeships); }
private async Task AddUkprnToProviderCache(long ukprn) { var cacheItem = await ukprnCache.TryGet(CacheKeys.ProvidersKey, CancellationToken.None); var ukprnList = cacheItem.HasValue ? cacheItem.Value : new List <long>(); if (!ukprnList.Contains(ukprn)) { ukprnList.Add(ukprn); } await ukprnCache.AddOrReplace(CacheKeys.ProvidersKey, ukprnList, CancellationToken.None); }
public async Task ProcessApprenticeshipUpdate(ApprenticeshipUpdated updatedApprenticeship) { logger.LogDebug( $"Getting apprenticeships cache item using uln for apprenticeship id: {updatedApprenticeship.Id}"); var cacheItem = await dataCache.TryGet(updatedApprenticeship.Uln.ToString(), CancellationToken.None); logger.LogDebug(cacheItem.HasValue ? "Item found in the cache." : "No cache item found. Will now create new apprenticeships list."); var apprenticeships = cacheItem.HasValue ? cacheItem.Value : new List <ApprenticeshipModel>(); logger.LogDebug("Removing old version of the apprenticeship."); apprenticeships.RemoveAll(apprenticeship => apprenticeship.Id == updatedApprenticeship.Id); logger.LogDebug("Now mapping the ApprenticeshipUpdated event to the ApprenticeshipModel."); var model = mapper.Map <ApprenticeshipModel>(updatedApprenticeship); logger.LogDebug("Finished mapping the apprenticeship model, now adding to the cache."); apprenticeships.Add(model); await dataCache.AddOrReplace(model.Uln.ToString(), apprenticeships, CancellationToken.None); logger.LogInfo( $"Finished storing the apprenticeship details in the cache. Apprenticeship id: {model.Id}, Account: {model.AccountId}, Provider: {model.Ukprn}"); await AddUkprnToProviderCache(updatedApprenticeship.Ukprn); }
public async Task <bool> UkprnExists(long ukprn) { var providersCacheItem = await ukprnCache.TryGet(CacheKeys.ProvidersKey).ConfigureAwait(false); return(providersCacheItem.HasValue && providersCacheItem.Value.Contains(ukprn)); }