package timecache

import (
	
	
	
)

// FirstSeenCache is a time cache that only marks the expiry of a message when first added.
type FirstSeenCache struct {
	lk  sync.RWMutex
	m   map[string]time.Time
	ttl time.Duration

	done func()
}

var _ TimeCache = (*FirstSeenCache)(nil)

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

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

	return 
}

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

func ( *FirstSeenCache) ( string) bool {
	.lk.RLock()
	defer .lk.RUnlock()

	,  := .m[]
	return 
}

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

	,  := .m[]
	if  {
		return false
	}

	.m[] = time.Now().Add(.ttl)
	return true
}