Documentation ¶
Overview ¶
Package lifetime provides specification of overridable TTLs.
Index ¶
Constants ¶
const ( // MaxDuration is the longest duration representable with time.Duration. // This can be used to create a TTL that is effectively infinite. MaxDuration time.Duration = 1<<63 - 1 )
Variables ¶
var ( // Zero is the canonical zero-duration lifetime. It should be returned // instead of nil when Lifetime is used as a value time. Note a // zero-duration lifetime can still be useful for indicating the creation // time of a value, which is why New doesn't return this value if the // duration is 0. Using this value in a comparison to check for a zero // duration is likely a bug. Zero = Lifetime{} )
Functions ¶
This section is empty.
Types ¶
type Lifetime ¶
type Lifetime struct { // Created is when the value was produced or retrieved in UTC. Created time.Time // TTL is the duration after Created for which the value is valid. TTL time.Duration }
Lifetime describes when a value was created, and the time from that instant that it expires. This should be used as an immutable value type.
We represent lifetimes as a time of creation, plus a duration (which is the literal TTL). This allows finding out when a value was created from its TTL, without having to embed it in the value. We require this at a library level for implementing TTL overrides.
func (Lifetime) Cap ¶
Cap imposes an upper limit on the lifetime from the point of creation. If the existing TTL is shorter than the cap, the original lifetime is returned.
func (Lifetime) Expired ¶
Expired returns true if the lifetime has passed, or false if it is still valid.