ccache/item.go
Karl Seguin 751266c34a Remove Value interface, cache now works against interface{} with the
expiry specified on a Set.

Get no longer returns expired items

Items can now be deleted
2013-10-30 20:18:51 +08:00

34 lines
582 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 || promotions == 0 {
return true
}
return false
}