2018-04-20 00:31:50 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2020-07-27 21:11:11 +00:00
|
|
|
|
|
|
|
"golang.org/x/time/rate"
|
2018-04-20 00:31:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// cacheEntry stores a single cache entry.
|
|
|
|
//
|
|
|
|
// Note that this isn't a very optimized structure currently. There are
|
|
|
|
// a lot of improvements that can be made here in the long term.
|
|
|
|
type cacheEntry struct {
|
|
|
|
// Fields pertaining to the actual value
|
|
|
|
Value interface{}
|
2019-01-10 12:46:11 +00:00
|
|
|
// State can be used to store info needed by the cache type but that should
|
|
|
|
// not be part of the result the client gets. For example the Connect Leaf
|
|
|
|
// type needs to store additional data about when it last attempted a renewal
|
|
|
|
// that is not part of the actual IssuedCert struct it returns. It's opaque to
|
|
|
|
// the Cache but allows types to store additional data that is coupled to the
|
|
|
|
// cache entry's lifetime and will be aged out by TTL etc.
|
|
|
|
State interface{}
|
2018-04-20 00:31:50 +00:00
|
|
|
Error error
|
|
|
|
Index uint64
|
|
|
|
|
|
|
|
// Metadata that is used for internal accounting
|
2018-05-09 18:10:17 +00:00
|
|
|
Valid bool // True if the Value is set
|
|
|
|
Fetching bool // True if a fetch is already active
|
|
|
|
Waiter chan struct{} // Closed when this entry is invalidated
|
2018-04-20 00:31:50 +00:00
|
|
|
|
2018-04-20 01:28:01 +00:00
|
|
|
// Expiry contains information about the expiration of this
|
|
|
|
// entry. This is a pointer as its shared as a value in the
|
2020-10-20 21:38:12 +00:00
|
|
|
// ExpiryHeap as well.
|
|
|
|
Expiry *CacheEntryExpiry
|
2018-09-06 10:34:28 +00:00
|
|
|
|
|
|
|
// FetchedAt stores the time the cache entry was retrieved for determining
|
|
|
|
// it's age later.
|
|
|
|
FetchedAt time.Time
|
|
|
|
|
|
|
|
// RefreshLostContact stores the time background refresh failed. It gets reset
|
|
|
|
// to zero after a background fetch has returned successfully, or after a
|
|
|
|
// background request has be blocking for at least 5 seconds, which ever
|
|
|
|
// happens first.
|
|
|
|
RefreshLostContact time.Time
|
2020-07-27 21:11:11 +00:00
|
|
|
// FetchRateLimiter limits the rate at which fetch is called for this entry.
|
|
|
|
FetchRateLimiter *rate.Limiter
|
2018-04-20 00:31:50 +00:00
|
|
|
}
|