func AddItem(key string, val *model.GraphItem) { itemlist, found := HistoryCache.Get(key) var slist *tlist.SafeListLimited if !found { slist = tlist.NewSafeListLimited(defaultHistorySize) HistoryCache.Put(key, slist) } else { slist = itemlist.(*tlist.SafeListLimited) } slist.PushFrontViolently(val) }
func AddItem(key string, val *cmodel.GraphItem) { itemlist, found := HistoryCache.Get(key) var slist *tlist.SafeListLimited if !found { slist = tlist.NewSafeListLimited(defaultHistorySize) HistoryCache.Put(key, slist) } else { slist = itemlist.(*tlist.SafeListLimited) } // old item should be drop first := slist.Front() if first == nil || first.(*cmodel.GraphItem).Timestamp < val.Timestamp { // first item or latest one slist.PushFrontViolently(val) } }