Example #1
0
        protected virtual async Task <DocumentWithDetailsDto> GetDocumentWithDetailsDto(
            Project project,
            string documentName,
            string version)
        {
            var cacheKey = $"Document@{project.ShortName}#{documentName}#{version}";

            return(await DocumentCache.GetOrAddAsync(
                       cacheKey,
                       async() =>
            {
                Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the store...");
                var store = _documentStoreFactory.Create(project.DocumentStoreType);
                var document = await store.GetDocumentAsync(project, documentName, version);
                Logger.LogInformation($"Document retrieved: {documentName}");
                return CreateDocumentWithDetailsDto(project, document);
            },
                       () => new DistributedCacheEntryOptions
            {
                //TODO: Configurable?
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2),
                SlidingExpiration = TimeSpan.FromMinutes(30)
            }
                       ));
        }
Example #2
0
        protected virtual async Task <DocumentWithDetailsDto> GetDocumentWithDetailsDtoAsync(
            Project project,
            string documentName,
            string languageCode,
            string version)
        {
            var cacheKey = $"Document@{project.ShortName}#{languageCode}#{documentName}#{version}";

            async Task <DocumentWithDetailsDto> GetDocumentAsync()
            {
                Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the store...");
                var store     = _documentStoreFactory.Create(project.DocumentStoreType);
                var languages = await GetLanguageListAsync(store, project, version);

                var language = GetLanguageByCode(languages, languageCode);
                var document = await store.GetDocumentAsync(project, documentName, language.Code, version);

                Logger.LogInformation($"Document retrieved: {documentName}");
                return(CreateDocumentWithDetailsDto(project, document, languages, language.Code));
            }

            if (Debugger.IsAttached)
            {
                return(await GetDocumentAsync());
            }

            return(await DocumentCache.GetOrAddAsync(
                       cacheKey,
                       GetDocumentAsync,
                       () => new DistributedCacheEntryOptions
            {
                //TODO: Configurable?
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2),
                SlidingExpiration = TimeSpan.FromMinutes(30)
            }
                       ));
        }
Example #3
0
        protected virtual async Task <DocumentWithDetailsDto> GetDocumentWithDetailsDtoAsync(
            Project project,
            string documentName,
            string languageCode,
            string version)
        {
            version = string.IsNullOrWhiteSpace(version) ? project.LatestVersionBranchName : version;

            var cacheKey = $"Document@{project.ShortName}#{languageCode}#{documentName}#{version}";

            async Task <DocumentWithDetailsDto> GetDocumentAsync()
            {
                Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the store...");
                var store    = _documentStoreFactory.Create(project.DocumentStoreType);
                var document = await store.GetDocumentAsync(project, documentName, languageCode, version);

                Logger.LogInformation($"Document retrieved: {documentName}");
                return(CreateDocumentWithDetailsDto(project, document));
            }

            if (HostEnvironment.IsDevelopment())
            {
                return(await GetDocumentAsync());
            }

            return(await DocumentCache.GetOrAddAsync(
                       cacheKey,
                       GetDocumentAsync,
                       () => new DistributedCacheEntryOptions
            {
                //TODO: Configurable?
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2),
                SlidingExpiration = TimeSpan.FromMinutes(30)
            }
                       ));
        }