MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Add

Method Add

internal/utils/expires/list.go:44–74  ·  view source on GitHub ↗

Add 添加条目 如果条目已经存在,则覆盖

(itemId uint64, expiresAt int64)

Source from the content-addressed store, hash-verified

42// Add 添加条目
43// 如果条目已经存在,则覆盖
44func (this *List) Add(itemId uint64, expiresAt int64) {
45 this.mu.Lock()
46 defer this.mu.Unlock()
47
48 if this.lastTimestamp == 0 || this.lastTimestamp > expiresAt {
49 this.lastTimestamp = expiresAt
50 }
51
52 // 是否已经存在
53 oldExpiresAt, ok := this.itemsMap[itemId]
54 if ok {
55 if oldExpiresAt == expiresAt {
56 return
57 }
58 delete(this.expireMap[oldExpiresAt], itemId)
59 if len(this.expireMap[oldExpiresAt]) == 0 {
60 delete(this.expireMap, oldExpiresAt)
61 }
62 }
63
64 expireItemMap, ok := this.expireMap[expiresAt]
65 if ok {
66 expireItemMap[itemId] = zero.New()
67 } else {
68 this.expireMap[expiresAt] = ItemMap{
69 itemId: zero.New(),
70 }
71 }
72
73 this.itemsMap[itemId] = expiresAt
74}
75
76func (this *List) Remove(itemId uint64) {
77 this.mu.Lock()

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected