Esempio n. 1
0
        public async Task <DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
        {
            var project = await _projectRepository.GetAsync(input.ProjectId);

            input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version;
            input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;

            var cacheKey = CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode, input.Version);

            async Task <DocumentResource> GetResourceAsync()
            {
                var source = _documentStoreFactory.Create(project.DocumentStoreType);

                return(await source.GetResource(project, input.Name, input.LanguageCode, input.Version));
            }

            if (HostEnvironment.IsDevelopment())
            {
                return(ObjectMapper.Map <DocumentResource, DocumentResourceDto>(await GetResourceAsync()));
            }

            return(ObjectMapper.Map <DocumentResource, DocumentResourceDto>(
                       await ResourceCache.GetOrAddAsync(
                           cacheKey,
                           GetResourceAsync,
                           () => new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = _documentResourceAbsoluteExpiration,
                SlidingExpiration = _documentResourceSlidingExpiration
            }
                           )
                       ));
        }