Esempio n. 1
0
        public async Task <IEnumerable <Story> > GetAsync()
        {
            var StoryLinks = new List <Story>();

            StoryLinks = _memoryCache.Get(cacheKey) as List <Story>;
            if (StoryLinks == null)
            {
                StoryLinks = new List <Story>();
                var storyIdsArray = await _http.GetStories();

                foreach (var id in storyIdsArray.Take(50))
                {
                    var story = await _http.GetStory(id);

                    if (story.Url?.Length > 7)
                    {
                        StoryLinks.Add(story);
                    }
                }

                _memoryCache.Set(cacheKey, StoryLinks, new MemoryCacheEntryOptions()
                                 .SetAbsoluteExpiration(TimeSpan.FromMinutes(2)));
            }

            return(StoryLinks.AsEnumerable());
        }