Source File
last_seen_cache.go
Belonging Package
github.com/libp2p/go-libp2p-pubsub/timecache
package timecacheimport ()// 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.Mutexm map[string]time.Timettl time.Durationdone 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}
![]() |
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. |