MCPcopy
hub / github.com/coocood/freecache / AverageAccessTime

Method AverageAccessTime

cache.go:359–370  ·  view source on GitHub ↗

AverageAccessTime returns the average unix timestamp when a entry being accessed. Entries have greater access time will be evacuated when it is about to be overwritten by new value.

()

Source from the content-addressed store, hash-verified

357// Entries have greater access time will be evacuated when it
358// is about to be overwritten by new value.
359func (cache *Cache) AverageAccessTime() int64 {
360 var entryCount, totalTime int64
361 for i := range cache.segments {
362 totalTime += atomic.LoadInt64(&cache.segments[i].totalTime)
363 entryCount += atomic.LoadInt64(&cache.segments[i].totalCount)
364 }
365 if entryCount == 0 {
366 return 0
367 } else {
368 return totalTime / entryCount
369 }
370}
371
372// HitCount is a metric that returns number of times a key was found in the cache.
373func (cache *Cache) HitCount() (count int64) {

Callers 4

TestFreeCacheFunction · 0.95
TestRaceFunction · 0.95

Calls

no outgoing calls

Tested by 4

TestFreeCacheFunction · 0.76
TestRaceFunction · 0.76