Exemplo n.º 1
0
        public Task <Chapter> GetChapterAsync(string chptId, string volId, string serId, bool forceRefresh = false)
        {
            if (!forceRefresh && ChapterCache.ContainsKey(chptId) && !ChapterCache[chptId].IsFaulted)
            {
                return(ChapterCache[chptId]);
            }
            if (ChapterCache.Count > MaxCachedUnit)
            {
                var outdates = (from item in ChapterCache where item.Value.IsCompleted select item.Key).ToArray();

                foreach (var key in outdates)
                {
                    ChapterCache.Remove(key);
                    if (ChapterCache.Count < MaxCachedUnit)
                    {
                        break;
                    }
                }
            }

            var task = GetAsync <Chapter>(
                ChaptersFolder,
                string.Format(ChapterFileName, chptId),
                () => LightKindomHtmlClient.GetChapterAsync(chptId, volId, serId),
                null, forceRefresh);

            ChapterCache[chptId] = task;
            CachedChapterSet.Add(chptId);
            return(task);
        }
 public static Task <Chapter> GetChapterAsync(string id, bool forceRefresh = false)
 {
     return(DataCache.GetAsync("chapter-" + id, () => LightKindomHtmlClient.GetChapterAsync(id)));
 }