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

Method recover

internal/stats/bandwidth_stat_manager.go:313–338  ·  view source on GitHub ↗

从本地缓存文件中恢复数据

()

Source from the content-addressed store, hash-verified

311
312// 从本地缓存文件中恢复数据
313func (this *BandwidthStatManager) recover() {
314 cacheData, err := os.ReadFile(this.cacheFile)
315 if err == nil {
316 var m = map[string]*BandwidthStat{}
317 err = json.Unmarshal(cacheData, &m)
318 if err == nil && len(m) > 0 {
319 var lastTime = ""
320 for _, stat := range m {
321 if stat.Day != fasttime.Now().Ymd() {
322 continue
323 }
324 if len(lastTime) == 0 || stat.TimeAt > lastTime {
325 lastTime = stat.TimeAt
326 }
327 }
328 if len(lastTime) > 0 {
329 var availableTime = timeutil.FormatTime("Hi", (time.Now().Unix()-300) /** 只保留5分钟的 **/ /300*300) // 300s = 5 minutes
330 if lastTime >= availableTime {
331 this.m = m
332 this.lastTime = lastTime
333 }
334 }
335 }
336 _ = os.Remove(this.cacheFile)
337 }
338}

Callers 1

StartMethod · 0.95

Calls 4

NowFunction · 0.92
YmdMethod · 0.80
UnixMethod · 0.80
RemoveMethod · 0.65

Tested by

no test coverage detected