Пример #1
0
        private void CleanCache()
        {
            List <GiftCache> cleanedGifts = new List <GiftCache>();

            lock (GiftCaches)
            {
                DateTime now = DateTime.UtcNow;
                while (GiftCaches.Count > 0)
                {
                    GiftCache gift = GiftCaches[0];
                    if (gift.ExpiredTime < now)
                    {
                        GiftCaches.RemoveAt(0);
                        cleanedGifts.Add(gift);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            for (int i = 0; i < cleanedGifts.Count; i++)
            {
                GiftCache gift = cleanedGifts[i];
                gift.OnExpire();
                CacheExpired?.Invoke(gift, gift);
            }
        }
Пример #2
0
        public GiftCache AppendCache(BiliLiveJsonParser.Gift gift)
        {
            GiftCache giftCache = new GiftCache(DateTime.UtcNow.AddSeconds(CacheExpireDuration))
            {
                UserId   = gift.Sender.Id,
                Username = gift.Sender.Name,
                GiftId   = gift.GiftId,
                GiftName = gift.GiftName,
                Number   = gift.Number,
                CoinType = gift.CoinType,
                Action   = gift.Action,
                FaceUri  = gift.FaceUri
            };

            GiftCaches.Add(giftCache);
            StartCacheManageThread();
            return(giftCache);
        }