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

Method Init

internal/caches/storage_memory.go:91–126  ·  view source on GitHub ↗

Init 初始化

()

Source from the content-addressed store, hash-verified

89
90// Init 初始化
91func (this *MemoryStorage) Init() error {
92 _ = this.list.Init()
93
94 this.list.OnAdd(func(item *Item) {
95 atomic.AddInt64(&this.usedSize, item.TotalSize())
96 })
97 this.list.OnRemove(func(item *Item) {
98 atomic.AddInt64(&this.usedSize, -item.TotalSize())
99 })
100
101 this.initPurgeTicker()
102
103 // 启动定时Flush memory to disk任务
104 if this.parentStorage != nil {
105 var threads = 2
106 var numCPU = runtime.NumCPU()
107 if fsutils.DiskIsExtremelyFast() {
108 if numCPU >= 8 {
109 threads = 8
110 } else {
111 threads = 4
112 }
113 } else if fsutils.DiskIsFast() {
114 if numCPU >= 4 {
115 threads = 4
116 }
117 }
118 for i := 0; i < threads; i++ {
119 goman.New(func() {
120 this.startFlush()
121 })
122 }
123 }
124
125 return nil
126}
127
128// OpenReader 读取缓存
129func (this *MemoryStorage) OpenReader(key string, useStale bool, isPartial bool) (Reader, error) {

Callers 1

Calls 7

initPurgeTickerMethod · 0.95
startFlushMethod · 0.95
NewFunction · 0.92
InitMethod · 0.65
OnAddMethod · 0.65
OnRemoveMethod · 0.65
TotalSizeMethod · 0.45

Tested by 1