Beispiel #1
0
        /// <summary>
        /// Gets the story.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public Story GetStory(int id)
        {
            if (MemoryCacheProvider.GetValue(id.ToString()) is Story story)
            {
                return(story);
            }

            story = _reader.GetStory(id);
            int cacheStoriesInDays = Convert.ToInt32(_configuration["CacheStoriesInDays"]);

            MemoryCacheProvider.Add(id.ToString(), story, DateTime.Now.AddDays(cacheStoriesInDays));
            return(story);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the best story ids.
        /// </summary>
        /// <param name="number">The number of ids to be returned.</param>
        /// <returns></returns>
        public IEnumerable <int> GetBestStoryIds(int number)
        {
            if (MemoryCacheProvider.GetValue("Ids") is IEnumerable <int> storyIds)
            {
                return(storyIds);
            }

            int numberOfStories = Convert.ToInt32(_configuration["NumberOfStories"]);

            storyIds = _reader.GetBestStoriesIds().Take(numberOfStories);
            int cacheIdsMinutes = Convert.ToInt32(_configuration["CacheIdsMinutes"]);

            MemoryCacheProvider.Add("Ids", storyIds, DateTime.Now.AddMinutes(cacheIdsMinutes));
            return(storyIds);
        }