Add method GetCacheBytes(c *cache) int

This commit is contained in:
hero0926 2017-11-15 14:16:56 +09:00
parent a3647f8e31
commit a8011e21b9
1 changed files with 12 additions and 0 deletions

View File

@ -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
}