Exemplo n.º 1
0
        public async Task <Series> GetIndexAsync(bool forceRefresh = false)
        {
            if (_indexUpdateTask != null)
            {
                return(await _indexUpdateTask);
            }

            if (Index == null || forceRefresh)
            {
                _indexUpdateTask = GetAsync(BookFolder, SeriesMetaFileName, () => LightKindomHtmlClient.GetSeriesAsync(_seriesId), TimeSpan.FromDays(7), forceRefresh).ContinueWith(ts =>
                {
                    Index            = ts.Result;
                    _indexUpdateTask = null;
                    return(ts.Result);
                });
                await _indexUpdateTask;
            }
            return(Index);
        }
        public static Task <Series> GetSeriesAsync(string id, bool forceRefresh = false)
        {
            if (forceRefresh == false && SeriesCache.ContainsKey(id) && !SeriesCache[id].IsFaulted)
            {
                return(SeriesCache[id]);
            }
            if (SeriesCache.Count > MaxCachedUnit)
            {
                var outdates = from item in SeriesCache where item.Value.IsCompleted select item.Key;
                foreach (var key in outdates)
                {
                    SeriesCache.Remove(key);
                    if (SeriesCache.Count < MaxCachedUnit)
                    {
                        break;
                    }
                }
            }

            var task = DataCache.GetAsync("series-" + id, () => LightKindomHtmlClient.GetSeriesAsync(id), DateTime.Now.AddDays(7), forceRefresh);

            SeriesCache[id] = task;
            return(task);
        }
 public static Task <Series> GetSeriesAsync(string id, bool forceRefresh = false)
 {
     return(DataCache.GetAsync("series-" + id, () => LightKindomHtmlClient.GetSeriesAsync(id)));
 }