Documentation
¶
Index ¶
- Constants
- type CacheManager
- type Flushable
- type InMemoryCacheManager
- func (c *InMemoryCacheManager[K, V]) Delete(ctx context.Context, keys ...string) error
- func (c *InMemoryCacheManager[K, V]) Flush(ctx context.Context) error
- func (c *InMemoryCacheManager[K, V]) Get(ctx context.Context, key string) (V, bool)
- func (c *InMemoryCacheManager[K, V]) GetMultiple(ctx context.Context, keys []string) (map[string]V, bool)
- func (c *InMemoryCacheManager[K, V]) GetWithRefresh(ctx context.Context, key string, ttl time.Duration) (V, bool)
- func (c *InMemoryCacheManager[K, V]) Set(ctx context.Context, key string, value V, ttl time.Duration)
- type ReadThroughCache
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
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 ¶
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 (*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
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]) GetWithRefresh ¶
Click to show internal directories.
Click to hide internal directories.