Documentation
¶
Index ¶
- type LevelCache
- type MultiLevelCache
- func (c *MultiLevelCache[K, V]) Build() *MultiLevelCache[K, V]
- func (c *MultiLevelCache[K, V]) Del(ctx context.Context, key K, opts ...OptFunc) error
- func (c *MultiLevelCache[K, V]) Get(ctx context.Context, key K, opts ...OptFunc) (V, bool, error)
- func (c *MultiLevelCache[K, V]) MDel(ctx context.Context, keys []K, opts ...OptFunc) error
- func (c *MultiLevelCache[K, V]) MGet(ctx context.Context, keys []K, opts ...OptFunc) (map[K]V, error)
- func (c *MultiLevelCache[K, V]) MSet(ctx context.Context, entities map[K]V, opts ...OptFunc) error
- func (c *MultiLevelCache[K, V]) Set(ctx context.Context, key K, value V, opts ...OptFunc) error
- func (c *MultiLevelCache[K, V]) Use(middleware cacher.Middleware[K, V]) *MultiLevelCache[K, V]
- type OptFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LevelCache ¶
type LevelCache[K comparable, V any] struct { Store cacher.Interface[K, V] Middlewares []cacher.Middleware[K, V] }
type MultiLevelCache ¶
type MultiLevelCache[K comparable, V any] struct { sync.RWMutex // contains filtered or unexported fields }
func NewMultiLevelCache ¶
func NewMultiLevelCache[K comparable, V any](stores ...cacher.Interface[K, V]) *MultiLevelCache[K, V]
func (*MultiLevelCache[K, V]) Build ¶
func (c *MultiLevelCache[K, V]) Build() *MultiLevelCache[K, V]
func (*MultiLevelCache[K, V]) Del ¶
func (c *MultiLevelCache[K, V]) Del(ctx context.Context, key K, opts ...OptFunc) error
func (*MultiLevelCache[K, V]) MDel ¶
func (c *MultiLevelCache[K, V]) MDel(ctx context.Context, keys []K, opts ...OptFunc) error
func (*MultiLevelCache[K, V]) MGet ¶
func (c *MultiLevelCache[K, V]) MGet(ctx context.Context, keys []K, opts ...OptFunc) (map[K]V, error)
func (*MultiLevelCache[K, V]) MSet ¶
func (c *MultiLevelCache[K, V]) MSet(ctx context.Context, entities map[K]V, opts ...OptFunc) error
func (*MultiLevelCache[K, V]) Set ¶
func (c *MultiLevelCache[K, V]) Set(ctx context.Context, key K, value V, opts ...OptFunc) error
func (*MultiLevelCache[K, V]) Use ¶
func (c *MultiLevelCache[K, V]) Use(middleware cacher.Middleware[K, V]) *MultiLevelCache[K, V]
type OptFunc ¶
type OptFunc func(*cacheOpts)
func WithFallbackOnLayerError ¶
func WithFallbackOnLayerError(shouldFallback func(ctx context.Context, info cacher.BaseInfo, err error) bool) OptFunc
WithFallbackOnLayerError sets whether to fallback to the next layer when an error occurs in the current layer (e.g., Redis connection failure). The function should return true to indicate fallback (default behavior), or false to return the error immediately.
func WithShouldSkipLayer ¶
WithShouldSkipLayer sets the rule for skipping a cache layer. When the shouldSkip function returns true, the corresponding cache layer will be skipped, and the query will proceed directly to the next layer.
Note: Cache levels are 1-based (e.g., Level 1, Level 2...), not 0-based.
Example: Skip Level 1 or a cache layer named "redis"
cache.Get(ctx, key, tiercache.WithShouldSkipLayer(func(ctx context.Context, info cacher.BaseInfo) bool {
// cacher.GetRunInfo(ctx).Level() gets the current level (starts from 1)
return cacher.GetRunInfo(ctx).Level() == 1 || info.Name() == "redis"
}))
Click to show internal directories.
Click to hide internal directories.