Documentation ¶
Index ¶
- func IsConflictErr(err error) bool
- type Cache
- func (cache *Cache[Value]) Clear()
- func (c *Cache[Value]) Has(lookup string, keyParts ...any) bool
- func (c *Cache[Value]) Invalidate(lookup string, keyParts ...any)
- func (c *Cache[Value]) Load(lookup string, load func() (Value, error), keyParts ...any) (Value, error)
- func (c *Cache[Value]) SetEvictionCallback(hook func(Value))
- func (c *Cache[Value]) SetInvalidateCallback(hook func(Value))
- func (c *Cache[Value]) SetTTL(ttl time.Duration, update bool)
- func (c *Cache[Value]) Start(freq time.Duration) bool
- func (c *Cache[Value]) Stop() bool
- func (c *Cache[Value]) Store(value Value, store func() error) error
- type ConflictError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConflictErr ¶
IsConflictErr returns whether error is due to key conflict.
Types ¶
type Cache ¶
type Cache[Value any] struct { // contains filtered or unexported fields }
Cache ...
func (*Cache[Value]) Clear ¶
func (cache *Cache[Value]) Clear()
Clear empties the cache, calling the invalidate callback.
func (*Cache[Value]) Invalidate ¶
Invalidate ...
func (*Cache[Value]) Load ¶
func (c *Cache[Value]) Load(lookup string, load func() (Value, error), keyParts ...any) (Value, error)
Load ...
func (*Cache[Value]) SetEvictionCallback ¶
func (c *Cache[Value]) SetEvictionCallback(hook func(Value))
SetEvictionCallback sets the eviction callback to the provided hook.
func (*Cache[Value]) SetInvalidateCallback ¶
func (c *Cache[Value]) SetInvalidateCallback(hook func(Value))
SetInvalidateCallback sets the invalidate callback to the provided hook.
func (*Cache[Value]) SetTTL ¶
SetTTL sets the cache item TTL. Update can be specified to force updates of existing items in the cache, this will simply add the change in TTL to their current expiry time.
func (*Cache[Value]) Start ¶
Start will start the cache background eviction routine with given sweep frequency. If already running or a freq <= 0 provided, this is a no-op. This will block until eviction routine started.
type ConflictError ¶
type ConflictError struct {
Key string
}
ConflictError is returned on cache key conflict.
func (ConflictError) Error ¶
func (c ConflictError) Error() string
Error returns the message for this key conflict error.