private async Task EnsureFeed()
 {
     if (_feed == null)
     {
         _feed = await GetOrCreateFeedCacheAsync();
     }
 }
        private async Task <MeetupFeed> GetOrCreateFeedCacheAsync()
        {
            MeetupFeed result = null;

            if (!_cache.TryGetValue <MeetupFeed>(_config.CacheKey, out result))
            {
                result = await GetFeedInternal();

                if (result != null)
                {
                    _cache.Set(
                        _config.CacheKey,
                        result,
                        TimeSpan.FromHours(_config.CacheDurationInSeconds));
                }
            }

            if (result == null)
            {
                throw new InvalidOperationException("failed to retrieve meetup feed");
            }


            return(result);
        }
        private async Task <MeetupFeed> GetFeedInternal()
        {
            var url        = string.Format(_config.FeedFormat, _config.NumberToGet, _config.ExpiryDays);
            var http       = _httpClientFactory.CreateClient();
            var jsonString = await http.GetStringAsync(url).ConfigureAwait(false);

            var list = JsonConvert.DeserializeObject <List <MeetupEvent> >(jsonString);
            var feed = new MeetupFeed();

            feed.Events = list;
            return(feed);
        }
Пример #4
0
        private async Task <MeetupFeed> GetFeedInternal()
        {
            var url        = string.Format(_config.FeedFormat);
            var http       = _httpClientFactory.CreateClient();
            var jsonString = await http.GetStringAsync(url).ConfigureAwait(false);

            var data = JsonConvert.DeserializeObject <MeetupEventData>(jsonString);
            var feed = new MeetupFeed();

            if (data != null)
            {
                feed.Events = data.Results;
            }
            return(feed);
        }