Documentation
¶
Overview ¶
Package cache implements a typed cache which can serve stale data while fetching fresh data, and which takes a distributed lock before attempting a refresh in order to greatly reduce possible cache stampede effects.
There is minimal support for multiple backends via NewCacheMultipleBackends. This is intended to be used for short durations to support migrating from one backend to another. It acquires pessimistic locks for write operations, so performance will be worse.
Data is stored in Redis, via the supplied Redis client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDoesNotExist is returned if negative caching is enabled and the // non-existence of the specified key has been cached. It must also be // returned by cache fetchers when the specified key does not exist and // negative caching is wanted. ErrDoesNotExist = errors.New("requested item does not exist") // ErrDisallowedCacheValue is thrown if a client attempts to set an entry in // the cache to the zero value of the cache type T. This is disallowed to // prevent accidentally poisoning the cache with invalid data. ErrDisallowedCacheValue = errors.New("nil and zero values are not permitted") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithNegativeCaching ¶
WithNegativeCaching configures the cache to allow caching of a negative ("does not exist") result for up to the specified duration.
func WithShadowWriteClient ¶
WithShadowWrite configures the cache to use a separate Redis client for shadow writes. This is useful for writing an additional copy of data to a different Redis instance than the primary instance used for caching.