示例#1
0
        public ActionResult Post(WordCountParams param)
        {
            // A very naive caching solution
            if (!_cache.TryGetValue(param.Text, out IEnumerable <WordCountItem> cacheEntry))
            {
                cacheEntry = _wordCountService.GetWordCounts(param.Text);

                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromHours(12));

                _cache.Set(param.Text, cacheEntry, cacheEntryOptions);
            }

            return(Ok(cacheEntry));
        }
示例#2
0
        public void GetWordCounts_EmptyInput()
        {
            var results = service.GetWordCounts(string.Empty);

            Assert.NotNull(results);
        }