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

Method increaseHit

internal/caches/storage_file.go:1442–1476  ·  view source on GitHub ↗

增加某个Key的点击量

(key string, hash string, reader Reader)

Source from the content-addressed store, hash-verified

1440
1441// 增加某个Key的点击量
1442func (this *FileStorage) increaseHit(key string, hash string, reader Reader) {
1443 var rate = this.policy.PersistenceHitSampleRate
1444 if rate <= 0 {
1445 rate = 1000
1446 }
1447 if rands.Int(0, rate) == 0 {
1448 var memoryStorage = this.memoryStorage
1449
1450 // 增加到热点
1451 // 这里不收录缓存尺寸过大的文件
1452 if memoryStorage != nil && reader.BodySize() > 0 && reader.BodySize() < (128<<20) {
1453 this.hotMapLocker.Lock()
1454 hotItem, ok := this.hotMap[key]
1455
1456 if ok {
1457 hotItem.Hits++
1458 } else if len(this.hotMap) < HotItemSize { // 控制数量
1459 this.hotMap[key] = &HotItem{
1460 Key: key,
1461 Hits: 1,
1462 }
1463 }
1464 this.hotMapLocker.Unlock()
1465
1466 // 只有重复点击的才增加点击量
1467 if ok {
1468 var hitErr = this.list.IncreaseHit(hash)
1469 if hitErr != nil {
1470 // 此错误可以忽略
1471 remotelogs.Error("CACHE", "increase hit failed: "+hitErr.Error())
1472 }
1473 }
1474 }
1475 }
1476}
1477
1478// 删除缓存文件
1479func (this *FileStorage) removeCacheFile(path string) error {

Callers 1

openReaderMethod · 0.95

Calls 6

ErrorFunction · 0.92
BodySizeMethod · 0.65
IncreaseHitMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected