Exemple #1
0
        public void EnsureFoldersExists()
        {
            if (ShouldNotPreload)
            {
                return;
            }

            _cache.EnsureFoldersExist(FundingFileSystemCacheKey.Folder, ProviderFundingFileSystemCacheKey.Folder);
        }
Exemple #2
0
        public async Task <IActionResult> FetchCoreProviderData(string specificationId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            bool fileSystemCacheEnabled = _scopedProvidersServiceSettings.IsFileSystemCacheEnabled;

            if (fileSystemCacheEnabled)
            {
                _fileSystemCache.EnsureFoldersExist(ScopedProvidersFileSystemCacheKey.Folder);
            }

            string filesystemCacheKey = $"{CacheKeys.ScopedProviderSummariesFilesystemKeyPrefix}{specificationId}";
            string cacheGuid          = await _cachePolicy.ExecuteAsync(() => _cacheProvider.GetAsync <string>(filesystemCacheKey));

            if (cacheGuid.IsNullOrEmpty())
            {
                cacheGuid = Guid.NewGuid().ToString();
                await _cacheProvider.SetAsync(filesystemCacheKey, cacheGuid, TimeSpan.FromDays(7), true);
            }

            ScopedProvidersFileSystemCacheKey cacheKey = new ScopedProvidersFileSystemCacheKey(specificationId, cacheGuid);

            if (fileSystemCacheEnabled && _fileSystemCache.Exists(cacheKey))
            {
                await using Stream cachedStream = _fileSystemCache.Get(cacheKey);

                return(GetActionResultForStream(cachedStream, specificationId));
            }

            IEnumerable <ProviderSummary> providerSummaries = await GetScopedProvidersForSpecification(specificationId);

            if (providerSummaries.IsNullOrEmpty())
            {
                return(new NoContentResult());
            }

            await using MemoryStream stream = new MemoryStream(providerSummaries.AsJsonBytes())
                        {
                            Position = 0
                        };

            if (fileSystemCacheEnabled)
            {
                _fileSystemCache.Add(cacheKey, stream);
            }

            return(GetActionResultForStream(stream, specificationId));
        }
        public async Task <IActionResult> GetAllProviders(string providerVersionId)
        {
            Guard.IsNullOrWhiteSpace(providerVersionId, nameof(providerVersionId));

            string blobName = $"{providerVersionId.ToLowerInvariant()}.json";

            bool fileSystemCacheEnabled = _providerVersionServiceSettings.IsFileSystemCacheEnabled;

            if (fileSystemCacheEnabled)
            {
                _fileSystemCache.EnsureFoldersExist(ProviderVersionFileSystemCacheKey.Folder);
            }

            ProviderVersionFileSystemCacheKey cacheKey = new ProviderVersionFileSystemCacheKey(providerVersionId);


            if (fileSystemCacheEnabled && _fileSystemCache.Exists(cacheKey))
            {
                await using Stream cachedStream = _fileSystemCache.Get(cacheKey);

                return(GetActionResultForStream(cachedStream, providerVersionId));
            }

            ICloudBlob blob = _blobClient.GetBlockBlobReference(blobName);

            if (!blob.Exists())
            {
                _logger.Error($"Failed to find blob with path: {blobName}");

                return(new NotFoundResult());
            }

            await using Stream blobClientStream = await _blobRepositoryPolicy.ExecuteAsync(()
                                                                                           => _blobClient.DownloadToStreamAsync(blob));

            if (fileSystemCacheEnabled)
            {
                _fileSystemCache.Add(cacheKey, blobClientStream);
            }

            return(GetActionResultForStream(blobClientStream, providerVersionId));
        }