ccache/item.go
Karl Seguin 6720535fab Checking if an item should be promoted because it's new is the uncommon
case which we can optimize out by being more explicit when we create
a new item
2013-11-13 13:46:41 +08:00

35 lines
563 B
Go
Executable file

package ccache
import (
"sync"
"time"
"sync/atomic"
"container/list"
)
type Item struct {
key string
sync.RWMutex
promotions int32
expires time.Time
value interface{}
element *list.Element
}
func newItem(key string, value interface{}, expires time.Time) *Item {
return &Item{
key: key,
value: value,
promotions: -1,
expires: expires,
}
}
func (i *Item) shouldPromote(getsPerPromote int32) bool {
promotions := atomic.AddInt32(&i.promotions, 1)
if promotions == getsPerPromote {
return true
}
return false
}