|
|
@ -235,7 +235,6 @@ func (c *cache) Decrement(k string, n int64) error {
|
|
|
|
return c.Increment(k, n*-1)
|
|
|
|
return c.Increment(k, n*-1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Deletes an item from the cache. Does nothing if the item does not exist in the cache.
|
|
|
|
// Deletes an item from the cache. Does nothing if the item does not exist in the cache.
|
|
|
|
func (c *cache) Delete(k string) {
|
|
|
|
func (c *cache) Delete(k string) {
|
|
|
|
c.mu.Lock()
|
|
|
|
c.mu.Lock()
|
|
|
@ -272,7 +271,6 @@ func (i *Item) Expired() bool {
|
|
|
|
return i.Expiration.Before(time.Now())
|
|
|
|
return i.Expiration.Before(time.Now())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (j *janitor) Run(c *cache) {
|
|
|
|
func (j *janitor) Run(c *cache) {
|
|
|
|
j.stop = make(chan bool)
|
|
|
|
j.stop = make(chan bool)
|
|
|
|
tick := time.Tick(j.Interval)
|
|
|
|
tick := time.Tick(j.Interval)
|
|
|
@ -316,9 +314,9 @@ func New(de, ci time.Duration) *Cache {
|
|
|
|
go j.Run(c)
|
|
|
|
go j.Run(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This trick ensures that the janitor goroutine (which--granted it was enabled--is
|
|
|
|
// This trick ensures that the janitor goroutine (which--granted it was enabled--is
|
|
|
|
// running DeleteExpired on c forever, if it was enabled) does not keep the returned C
|
|
|
|
// running DeleteExpired on c forever) does not keep the returned C object from being
|
|
|
|
// object from being garbage collected. When it is garbage collected, the finalizer stops
|
|
|
|
// garbage collected. When it is garbage collected, the finalizer stops the janitor
|
|
|
|
// the janitor goroutine, after which c is collected.
|
|
|
|
// goroutine, after which c is collected.
|
|
|
|
C := &Cache{c}
|
|
|
|
C := &Cache{c}
|
|
|
|
if ci > 0 {
|
|
|
|
if ci > 0 {
|
|
|
|
runtime.SetFinalizer(C, stopJanitor)
|
|
|
|
runtime.SetFinalizer(C, stopJanitor)
|
|
|
|