Exemple #1
0
        public async Task <SearchInfo> AddOrUpdate(string key, Func <Task <string> > valueFactory)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("message", nameof(key));
            }

            if (valueFactory is null)
            {
                throw new ArgumentNullException(nameof(valueFactory));
            }

            var searchInfo = Get(key);

            string jsonResult;

            if (searchInfo is null)
            {
                jsonResult = await valueFactory();

                searchInfo = new SearchInfo(key, jsonResult);
                if (!string.IsNullOrWhiteSpace(jsonResult))
                {
                    Add(searchInfo);
                }
            }

            return(searchInfo);
        }
Exemple #2
0
        public void Remove(SearchInfo searchResult)
        {
            if (searchResult is null)
            {
                throw new ArgumentNullException(nameof(searchResult));
            }

            _cache.Remove(searchResult);
        }
Exemple #3
0
        public void Add(SearchInfo searchResult)
        {
            if (searchResult is null)
            {
                throw new ArgumentNullException(nameof(searchResult));
            }

            _cache.AddOrUpdate(searchResult, SearchInfo.DefaultComparer);
        }