Source File
time_cache.go
Belonging Package
github.com/libp2p/go-libp2p-pubsub/timecache
package timecacheimport ()// Stategy is the TimeCache expiration strategy to use.type Strategy uint8const (// Strategy_FirstSeen expires an entry from the time it was added.Strategy_FirstSeen Strategy = iota// Stategy_LastSeen expires an entry from the last time it was touched by an Add or Has.Strategy_LastSeen)// TimeCache is a cahe of recently seen messages (by id).type TimeCache interface {// Add adds an id into the cache, if it is not already there.// Returns true if the id was newly added to the cache.// Depending on the implementation strategy, it may or may not update the expiry of// an existing entry.Add(string) bool// Has checks the cache for the presence of an id.// Depending on the implementation strategy, it may or may not update the expiry of// an existing entry.Has(string) bool// Done signals that the user is done with this cache, which it may stop background threads// and relinquish resources.Done()}// NewTimeCache defaults to the original ("first seen") cache implementationfunc ( time.Duration) TimeCache {return NewTimeCacheWithStrategy(Strategy_FirstSeen, )}func ( Strategy, time.Duration) TimeCache {switch {case Strategy_FirstSeen:return newFirstSeenCache()case Strategy_LastSeen:return newLastSeenCache()default:// Default to the original time cache implementationreturn newFirstSeenCache()}}
![]() |
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. |