Source File
first_seen_cache.go
Belonging Package
github.com/libp2p/go-libp2p-pubsub/timecache
package timecacheimport ()// FirstSeenCache is a time cache that only marks the expiry of a message when first added.type FirstSeenCache struct {lk sync.RWMutexm map[string]time.Timettl time.Durationdone 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}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |