Documentation ¶
Index ¶
- Variables
- type Cache
- func (c Cache[V]) Clear(ctx context.Context)
- func (c Cache[V]) Get(ctx context.Context, key any) (V, bool)
- func (c Cache[V]) GetOrProvide(ctx context.Context, key any, valueProvider ValueProvider[V]) (V, bool)
- func (c Cache[V]) GetOrProvideAsync(ctx context.Context, key any, valueProvider ValueProvider[V], defaultValue V) (V, bool)
- func (c Cache[V]) Remove(ctx context.Context, key any)
- type CacheItem
- type CacheKeyGenerator
- type CacheMonitoring
- type Cacher
- type GlobalCacheKeyGenerator
- type GlobalKeysCache
- func (t GlobalKeysCache[V]) Clear(ctx context.Context)
- func (t GlobalKeysCache[V]) Get(ctx context.Context, key any) (V, bool)
- func (t GlobalKeysCache[V]) GetOrProvide(ctx context.Context, key any, valueProvider ValueProvider[V]) (V, bool)
- func (t GlobalKeysCache[V]) GetOrProvideAsync(ctx context.Context, key any, valueProvider ValueProvider[V], defaultValue V) (V, bool)
- func (t GlobalKeysCache[V]) Remove(ctx context.Context, key any)
- type NopCacheMonitoring
- func (n NopCacheMonitoring) ClearFailed(ctx context.Context)
- func (n NopCacheMonitoring) GetFailed(ctx context.Context, key any, err error)
- func (n NopCacheMonitoring) Hit(ctx context.Context, key any)
- func (n NopCacheMonitoring) Miss(ctx context.Context, key any)
- func (n NopCacheMonitoring) PutFailed(ctx context.Context, key any, err error)
- func (n NopCacheMonitoring) RemoveFailed(ctx context.Context, key any)
- type SimpleCache
- type SimpleValueProvider
- type TwoLevelCache
- func (t TwoLevelCache[V]) Clear(ctx context.Context)
- func (t TwoLevelCache[V]) Get(ctx context.Context, key any) (V, bool)
- func (t TwoLevelCache[V]) GetOrProvide(ctx context.Context, key any, valueProvider ValueProvider[V]) (V, bool)
- func (t TwoLevelCache[V]) GetOrProvideAsync(ctx context.Context, key any, valueProvider ValueProvider[V], defaultValue V) (V, bool)
- func (t TwoLevelCache[V]) Remove(ctx context.Context, key any)
- type ValueProvider
Constants ¶
This section is empty.
Variables ¶
View Source
var InvalidCacheKeyErr = errors.New("cache key should be string or implement \"GetCacheKey() string\" method")
Functions ¶
This section is empty.
Types ¶
type Cache ¶ added in v2.0.14
type Cache[V any] struct { // contains filtered or unexported fields }
func NewCache ¶ added in v2.0.14
func NewCache[V any](back SimpleCache, now func() time.Time) *Cache[V]
func (Cache[V]) GetOrProvide ¶ added in v2.0.14
func (Cache[V]) GetOrProvideAsync ¶ added in v2.0.14
type CacheItem ¶ added in v2.0.14
type CacheItem[V any] struct { // contains filtered or unexported fields }
type CacheKeyGenerator ¶ added in v2.0.14
type CacheKeyGenerator interface {
GetCacheKey() string
}
func NewGlobalCacheKeyGenerator ¶ added in v2.0.14
func NewGlobalCacheKeyGeneratorFromPrefix ¶ added in v2.0.14
func NewGlobalCacheKeyGeneratorFromPrefix(prefix string, key any) (CacheKeyGenerator, error)
type CacheMonitoring ¶
type Cacher ¶
type Cacher[V any] interface { GetOrProvide(ctx context.Context, key any, valueProvider ValueProvider[V]) (V, bool) GetOrProvideAsync(ctx context.Context, key any, valueProvider ValueProvider[V], defaultValue V) (V, bool) Get(ctx context.Context, key any) (V, bool) Remove(ctx context.Context, key any) Clear(ctx context.Context) }
type GlobalCacheKeyGenerator ¶ added in v2.0.14
type GlobalCacheKeyGenerator struct {
// contains filtered or unexported fields
}
func (*GlobalCacheKeyGenerator) GetCacheKey ¶ added in v2.0.14
func (g *GlobalCacheKeyGenerator) GetCacheKey() string
type GlobalKeysCache ¶ added in v2.0.14
type GlobalKeysCache[V any] struct { // contains filtered or unexported fields }
func NewGlobalKeysCache ¶ added in v2.0.14
func (GlobalKeysCache[V]) Clear ¶ added in v2.0.14
func (t GlobalKeysCache[V]) Clear(ctx context.Context)
func (GlobalKeysCache[V]) Get ¶ added in v2.0.14
func (t GlobalKeysCache[V]) Get(ctx context.Context, key any) (V, bool)
func (GlobalKeysCache[V]) GetOrProvide ¶ added in v2.0.14
func (t GlobalKeysCache[V]) GetOrProvide(ctx context.Context, key any, valueProvider ValueProvider[V]) (V, bool)
func (GlobalKeysCache[V]) GetOrProvideAsync ¶ added in v2.0.14
func (t GlobalKeysCache[V]) GetOrProvideAsync(ctx context.Context, key any, valueProvider ValueProvider[V], defaultValue V) (V, bool)
type NopCacheMonitoring ¶
type NopCacheMonitoring struct { }
func (NopCacheMonitoring) ClearFailed ¶
func (n NopCacheMonitoring) ClearFailed(ctx context.Context)
func (NopCacheMonitoring) GetFailed ¶
func (n NopCacheMonitoring) GetFailed(ctx context.Context, key any, err error)
func (NopCacheMonitoring) PutFailed ¶
func (n NopCacheMonitoring) PutFailed(ctx context.Context, key any, err error)
func (NopCacheMonitoring) RemoveFailed ¶
func (n NopCacheMonitoring) RemoveFailed(ctx context.Context, key any)
type SimpleCache ¶ added in v2.0.14
type SimpleCache interface { // Set adds a key-value pair to the cache. // Returns false if key was not set because of some reason Set(key any, value any) bool // Get retrieves a value from the cache by its key. Get(key any) (any, bool) // Remove removes a key-value pair from the cache. Remove(key any) // Clear clears all key-value pairs from the cache. Clear() // SetWithTTL works like Set but adds a key-value pair to the cache that will expire after the specified TTL // (time to live) has passed. A zero value means the value never expires, which is identical to calling Set. // A negative value is a no-op and the value is discarded. SetWithTTL(key any, value any, ttl time.Duration) bool }
SimpleCache is an interface for a simple cache that can store key-value pairs.
type SimpleValueProvider ¶ added in v2.0.11
type TwoLevelCache ¶ added in v2.0.14
type TwoLevelCache[V any] struct { // contains filtered or unexported fields }
func NewTwoLevelCache ¶ added in v2.0.14
func NewTwoLevelCache[V any](front Cacher[V], back Cacher[V]) *TwoLevelCache[V]
func (TwoLevelCache[V]) Clear ¶ added in v2.0.14
func (t TwoLevelCache[V]) Clear(ctx context.Context)
func (TwoLevelCache[V]) Get ¶ added in v2.0.14
func (t TwoLevelCache[V]) Get(ctx context.Context, key any) (V, bool)
func (TwoLevelCache[V]) GetOrProvide ¶ added in v2.0.14
func (t TwoLevelCache[V]) GetOrProvide(ctx context.Context, key any, valueProvider ValueProvider[V]) (V, bool)
func (TwoLevelCache[V]) GetOrProvideAsync ¶ added in v2.0.14
func (t TwoLevelCache[V]) GetOrProvideAsync(ctx context.Context, key any, valueProvider ValueProvider[V], defaultValue V) (V, bool)
type ValueProvider ¶
type ValueProvider[V any] func(ctx context.Context, key any) (ok bool, val V, actualTTL time.Duration, usableTTL time.Duration)
ValueProvider is a function that provides a value for a given key, along with the actual and usable TTLs.
The function takes a key of type K and returns a value of type V, along with the actual TTL and usable TTL, or an error if the value could not be provided.
Context should be used by provider to properly process cancellation, e.g. because of timeout.
func FixedTTLProvider ¶ added in v2.0.11
func SimpleFixedTTLProvider ¶ added in v2.0.11
func (*ValueProvider[V]) WithRemoteCache ¶ added in v2.0.11
func (p *ValueProvider[V]) WithRemoteCache( remoteCache Cacher[V], baseProvider ValueProvider[V], ) ValueProvider[V]
Click to show internal directories.
Click to hide internal directories.