| 78 | } |
| 79 | |
| 80 | func (this *Stat) IncreaseCached(category string) { |
| 81 | this.mu.RLock() |
| 82 | var item = this.itemMap[category] |
| 83 | if item != nil { |
| 84 | if item.isGood || item.isBad { |
| 85 | this.mu.RUnlock() |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | atomic.AddUint64(&item.countCached, 1) |
| 90 | this.mu.RUnlock() |
| 91 | return |
| 92 | } |
| 93 | this.mu.RUnlock() |
| 94 | |
| 95 | this.mu.Lock() |
| 96 | |
| 97 | if len(this.itemMap) > this.maxItems { |
| 98 | // remove one randomly |
| 99 | for k := range this.itemMap { |
| 100 | delete(this.itemMap, k) |
| 101 | break |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | this.itemMap[category] = &Item{ |
| 106 | countHits: 0, |
| 107 | countCached: 1, |
| 108 | timestamp: fasttime.Now().Unix(), |
| 109 | } |
| 110 | this.mu.Unlock() |
| 111 | } |
| 112 | |
| 113 | func (this *Stat) IncreaseHit(category string) { |
| 114 | this.mu.RLock() |