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

Method Add

internal/caches/list_memory.go:60–90  ·  view source on GitHub ↗
(hash string, item *Item)

Source from the content-addressed store, hash-verified

58}
59
60func (this *MemoryList) Add(hash string, item *Item) error {
61 this.locker.Lock()
62
63 prefix := this.prefix(hash)
64 itemMap, ok := this.itemMaps[prefix]
65 if !ok {
66 itemMap = map[string]*Item{}
67 this.itemMaps[prefix] = itemMap
68 }
69
70 // 先删除,为了可以正确触发统计
71 oldItem, ok := itemMap[hash]
72 if ok {
73 // 回调
74 if this.onRemove != nil {
75 this.onRemove(oldItem)
76 }
77 } else {
78 atomic.AddInt64(&this.count, 1)
79 }
80
81 // 添加
82 if this.onAdd != nil {
83 this.onAdd(item)
84 }
85
86 itemMap[hash] = item
87
88 this.locker.Unlock()
89 return nil
90}
91
92func (this *MemoryList) Exist(hash string) (bool, int64, error) {
93 this.locker.RLock()

Callers 2

TestMemoryList_StatFunction · 0.95

Calls 3

prefixMethod · 0.95
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 2

TestMemoryList_StatFunction · 0.76