| 1 | package gcachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/ |
| 2 | |
| 3 | import ( |
| 4 | "sync/atomicscip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/" |
| 5 | ) |
| 6 | |
| 7 | type statsAccessorscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/statsAccessor# interface { |
| 8 | HitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/statsAccessor#HitCount.() uint64 |
| 9 | MissCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/statsAccessor#MissCount.() uint64 |
| 10 | LookupCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/statsAccessor#LookupCount.() uint64 |
| 11 | HitRatescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/statsAccessor#HitRate.() float64 |
| 12 | } |
| 13 | |
| 14 | // statistics |
| 15 | type statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats# struct { |
| 16 | hitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#hitCount. uint64 |
| 17 | missCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#missCount. uint64 |
| 18 | } |
| 19 | |
| 20 | // increment hit count |
| 21 | func (st *statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#) IncrHitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#IncrHitCount().() uint64 { |
| 22 | return atomicscip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/.AddUint64scip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/AddUint64().(&st.hitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#hitCount., 1) |
| 23 | } |
| 24 | |
| 25 | // increment miss count |
| 26 | func (st *statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#) IncrMissCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#IncrMissCount().() uint64 { |
| 27 | return atomicscip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/.AddUint64scip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/AddUint64().(&st.missCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#missCount., 1) |
| 28 | } |
| 29 | |
| 30 | // HitCount returns hit count |
| 31 | func (st *statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#) HitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#HitCount().() uint64 { |
| 32 | return atomicscip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/.LoadUint64scip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/LoadUint64().(&st.hitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#hitCount.) |
| 33 | } |
| 34 | |
| 35 | // MissCount returns miss count |
| 36 | func (st *statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#) MissCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#MissCount().() uint64 { |
| 37 | return atomicscip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/.LoadUint64scip-go gomod github.com/golang/go/src go1.15 `sync/atomic`/LoadUint64().(&st.missCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#missCount.) |
| 38 | } |
| 39 | |
| 40 | // LookupCount returns lookup count |
| 41 | func (st *statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#) LookupCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#LookupCount().() uint64 { |
| 42 | return st.HitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#HitCount().() + st.MissCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#MissCount().() |
| 43 | } |
| 44 | |
| 45 | // HitRate returns rate for cache hitting |
| 46 | func (st *statsscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#) HitRatescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#HitRate().() float64 { |
| 47 | hc, mc := st.HitCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#HitCount().(), st.MissCountscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/stats#MissCount().() |
| 48 | total := hc + mc |
| 49 | if total == 0 { |
| 50 | return 0.0 |
| 51 | } |
| 52 | return float64(hc) / float64(total) |
| 53 | } |