diff --git a/cache.go b/cache.go index db88d2f..dfa49ca 100644 --- a/cache.go +++ b/cache.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "reflect" "runtime" "sync" "time" @@ -1159,3 +1160,14 @@ func New(defaultExpiration, cleanupInterval time.Duration) *Cache { func NewFrom(defaultExpiration, cleanupInterval time.Duration, items map[string]Item) *Cache { return newCacheWithJanitor(defaultExpiration, cleanupInterval, items) } + +// Return a Bytes cache has as int. +// To Evaluate memory and cache usage. +func GetCacheBytes(c *cache) int { + + cacheitems := c.Items() + ptrcachebyte := uintptr(len(cacheitems)) * reflect.TypeOf(cacheitems).Elem().Size() + cachebyte := int(ptrcachebyte) + + return cachebyte +}