From a8011e21b9365aa23e5beb2184cd4f5659869bcd Mon Sep 17 00:00:00 2001 From: hero0926 Date: Wed, 15 Nov 2017 14:16:56 +0900 Subject: [PATCH] Add method GetCacheBytes(c *cache) int --- cache.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 +}