package timecache

import (
	
	
	
)

// LastSeenCache is a time cache that extends the expiry of a seen message when added
// or checked for presence with Has..
type LastSeenCache struct {
	lk  sync.Mutex
	m   map[string]time.Time
	ttl time.Duration

	done func()
}

var _ TimeCache = (*LastSeenCache)(nil)

func newLastSeenCache( time.Duration) *LastSeenCache {
	 := &LastSeenCache{
		m:   make(map[string]time.Time),
		ttl: ,
	}

	,  := context.WithCancel(context.Background())
	.done = 
	go background(, &.lk, .m)

	return 
}

func ( *LastSeenCache) () {
	.done()
}

func ( *LastSeenCache) ( string) bool {
	.lk.Lock()
	defer .lk.Unlock()

	,  := .m[]
	.m[] = time.Now().Add(.ttl)

	return !
}

func ( *LastSeenCache) ( string) bool {
	.lk.Lock()
	defer .lk.Unlock()

	,  := .m[]
	if  {
		.m[] = time.Now().Add(.ttl)
	}

	return 
}