cachemanager

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCleanupInterval = 30 * time.Minute
View Source
const DefaultExpiration = 10 * time.Minute

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheManager

type CacheManager[K comparable, V any] interface {
	Get(ctx context.Context, key K) (V, bool)
	GetMultiple(ctx context.Context, keys []K) (map[K]V, bool)
	GetWithRefresh(ctx context.Context, key K, ttl time.Duration) (V, bool)
	Set(ctx context.Context, key K, value V, ttl time.Duration)
	Delete(ctx context.Context, keys ...K) error
	Flush(ctx context.Context) error
}

type Flushable added in v0.8.0

type Flushable interface {
	Flush(ctx context.Context) error
}

Flushable is a non-generic interface for flushing a cache. This is useful when the app layer needs to flush caches without knowing the concrete key/value types (e.g. BQL caches parameterized on beads types).

type InMemoryCacheManager

type InMemoryCacheManager[K ~string, V any] struct {
	// contains filtered or unexported fields
}

InMemoryCacheManager is the concrete implementation of the CacheManager interface

func NewInMemoryCacheManager

func NewInMemoryCacheManager[K ~string, V any](useCase string, defaultExpiration, cleanupInterval time.Duration) *InMemoryCacheManager[K, V]

NewInMemoryCacheManager initializes the in-memory cache with a default cleanup interval

func (*InMemoryCacheManager[K, V]) Delete

func (c *InMemoryCacheManager[K, V]) Delete(ctx context.Context, keys ...string) error

Delete remove a value in the cache by its key

func (*InMemoryCacheManager[K, V]) Flush

func (c *InMemoryCacheManager[K, V]) Flush(ctx context.Context) error

Delete remove a value in the cache by its key

func (*InMemoryCacheManager[K, V]) Get

func (c *InMemoryCacheManager[K, V]) Get(ctx context.Context, key string) (V, bool)

Get retrieves an item from the cache by its key

func (*InMemoryCacheManager[K, V]) GetMultiple

func (c *InMemoryCacheManager[K, V]) GetMultiple(ctx context.Context, keys []string) (map[string]V, bool)

func (*InMemoryCacheManager[K, V]) GetWithRefresh

func (c *InMemoryCacheManager[K, V]) GetWithRefresh(ctx context.Context, key string, ttl time.Duration) (V, bool)

GetWithRefresh retrieves an item from the cache if one is found we extend the ttl by putting the item back in the cache

func (*InMemoryCacheManager[K, V]) Set

func (c *InMemoryCacheManager[K, V]) Set(ctx context.Context, key string, value V, ttl time.Duration)

Set sets a value in the cache with a key and TTL

type ReadThroughCache

type ReadThroughCache[K comparable, V any, I any] struct {
	// contains filtered or unexported fields
}

func NewReadThroughCache

func NewReadThroughCache[K comparable, V any, I any](
	cache CacheManager[K, V],
	fn func(ctx context.Context, input I) (V, error),
	shouldSkipCache bool,
) *ReadThroughCache[K, V, I]

func (*ReadThroughCache[K, V, I]) Get

func (r *ReadThroughCache[K, V, I]) Get(ctx context.Context, key K, input I, ttl time.Duration) (V, error)

func (*ReadThroughCache[K, V, I]) GetWithRefresh

func (r *ReadThroughCache[K, V, I]) GetWithRefresh(ctx context.Context, key K, input I, ttl time.Duration) (V, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL