Fix max cache size calculation when system RAM is inferior to the default cache size (#3410)

This commit is contained in:
Anis Elleuch 2016-12-07 01:09:26 +01:00 committed by Harshavardhana
parent 5c9a95df32
commit 0cef971832
2 changed files with 4 additions and 1 deletions

View File

@ -77,7 +77,7 @@ func setMaxMemory() error {
return err
}
if err == nil && stats.TotalRAM < globalMaxCacheSize {
globalMaxCacheSize = (80 / 100) * stats.TotalRAM
globalMaxCacheSize = uint64(float64(80*stats.TotalRAM) / 100)
}
return nil
}

View File

@ -73,6 +73,9 @@ type Cache struct {
// the items in the cache never expire (by default), and must be deleted
// manually.
func New(maxSize uint64, expiry time.Duration) *Cache {
if maxSize == 0 {
panic("objcache: setting maximum cache size to zero is forbidden.")
}
C := &Cache{
maxSize: maxSize,
entries: make(map[string]*buffer),