Documentation
¶
Overview ¶
Package shortcache holds one value read from the database for a short while, so the requests in between share it rather than each asking.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache keeps one value for TTL. Concurrent readers of an expired value share one load rather than each running it, and Clear makes the next read load afresh. The zero value is not usable; build one with New.
func (*Cache[T]) Clear ¶
func (c *Cache[T]) Clear()
Clear forgets the value, so the next Get loads it again.
func (*Cache[T]) Get ¶
Get returns the cached value while it is fresh, and otherwise the result of load — run once however many callers are waiting for it.
When load fails, Get returns its error along with the last value it held, if any: stale is usually better than nothing for a caller that can say so, and stale reports which it got.
A load is tied to the generation it began in. One still running when Clear is called neither stores its result nor serves callers that arrive after the Clear: those start a load of their own, so a request made after a write never gets an answer read before it.