This commit is contained in:
Ten 2017-11-15 05:20:51 +00:00 committed by GitHub
commit 24d235895f
1 changed files with 12 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"reflect"
"runtime" "runtime"
"sync" "sync"
"time" "time"
@ -1159,3 +1160,14 @@ func New(defaultExpiration, cleanupInterval time.Duration) *Cache {
func NewFrom(defaultExpiration, cleanupInterval time.Duration, items map[string]Item) *Cache { func NewFrom(defaultExpiration, cleanupInterval time.Duration, items map[string]Item) *Cache {
return newCacheWithJanitor(defaultExpiration, cleanupInterval, items) 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
}