示例#1
0
        public async Task <WorkIndexing> Work(int workId)
        {
            var webDocument = await _client.GetWork(workId);

            Work cachedWork = null;

            if (_cache.TryGetValue("WorksCache", out List <Work> cachedWorks))
            {
                cachedWork = cachedWorks.FirstOrDefault(work => work.WorkId == workId);
            }

            var workAdapted = WorkAdapter.ExtractWork(webDocument);

            if (cachedWork is null)
            {
                return(workAdapted);
            }
            workAdapted.Title    = cachedWork.Title;
            workAdapted.Comments = cachedWork.Comments;
            workAdapted.Kudos    = cachedWork.Kudos;
            workAdapted.Fandom   = cachedWork.Fandom;
            workAdapted.Language = cachedWork.Language;
            workAdapted.Link     = cachedWork.Link;
            workAdapted.Words    = cachedWork.Words;
            _cache.GetOrCreate("WorkIndexedCache", entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(15);
                entry.SetPriority(CacheItemPriority.High);
                return(workAdapted);
            });
            return(workAdapted);
        }
示例#2
0
        public async Task <List <Work> > Works()
        {
            var webDocument = await _client.GetWorks();

            _cache.GetOrCreate("WorksCache", entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(15);
                entry.SetPriority(CacheItemPriority.High);
                return(WorkAdapter.ExtractWorks(webDocument));
            });
            return(WorkAdapter.ExtractWorks(webDocument));
        }
示例#3
0
        public async Task <List <Work> > Search(SearchRequest request)
        {
            var searchPattern = request.Query is null ? "" : Regex.Replace(request.Query, @"\s+|\,+", "+");

            searchPattern += string.IsNullOrEmpty(request.Page) ? "&page=1" : $"&page={request.Page}";
            var webDocument = await _client.GetWorks(searchPattern);

            var works = WorkAdapter.ExtractWorks(webDocument);

            _cache.GetOrCreate("WorksCache", entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(15);
                entry.SetPriority(CacheItemPriority.High);
                return(works);
            });
            return(works);
        }