示例#1
0
        private async Task <Story> GetStoryFromCache(int storyId, bool disableCache)
        {
            Story story;

            if (disableCache == true)
            {
                story = await _hackerNewsApi.GetStoryById(storyId);
            }
            else
            {
                _storyCache.TryGetValue(storyId, out story);

                if (story == null)
                {
                    story = await _hackerNewsApi.GetStoryById(storyId);

                    _storyCache.TryAdd(storyId, story);
                }
            }

            return(story);
        }