Esempio n. 1
0
        public List <string> GetAnagramsFromCache(string input) // returns anagrams from cache or db
        {
            var resultList = new List <string>();

            var cacheList = _anagramCache.SearchCacheForAnagrams(input);

            if (cacheList.Count == 0)     // if word isn't cached use get anagrams and cache
            {
                var anagramList = _anagramSolverService.GetAnagrams(input);
                AddCacheToRepository(anagramList, input);
                foreach (string anagramWord in anagramList)
                {
                    resultList.Add(anagramWord);
                }
                anagramList.Clear();
            }
            else
            {
                foreach (string cacheWord in cacheList)
                {
                    resultList.Add(cacheWord);
                }
            }

            return(resultList);
        }