Documentation
¶
Index ¶
- Constants
- type CacheManager
- type CacheManagerMock
- func (m *CacheManagerMock[K, V]) Delete(ctx context.Context, keys ...K) error
- func (m *CacheManagerMock[K, V]) Flush(ctx context.Context) error
- func (m *CacheManagerMock[K, V]) Get(ctx context.Context, key K) (V, bool)
- func (m *CacheManagerMock[K, V]) GetMultiple(ctx context.Context, keys []K) (map[K]V, bool)
- func (m *CacheManagerMock[K, V]) GetWithRefresh(ctx context.Context, key K, ttl time.Duration) (V, bool)
- func (m *CacheManagerMock[K, V]) Set(ctx context.Context, key K, value V, ttl time.Duration)
- 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)
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 CacheManagerMock ¶
type CacheManagerMock[K comparable, V any] struct { GetFunc func(ctx context.Context, key K) (V, bool) GetMultipleFunc func(ctx context.Context, keys []K) (map[K]V, bool) GetWithRefreshFunc func(ctx context.Context, key K, ttl time.Duration) (V, bool) SetFunc func(ctx context.Context, key K, value V, ttl time.Duration) DeleteFunc func(ctx context.Context, keys ...K) error FlushFunc func(ctx context.Context) error }
CacheManagerMock is a mock implementation of CacheManager for testing. This uses the function-field pattern consistent with moq-generated mocks. Note: moq doesn't support generic interfaces, so this is hand-written.
func (*CacheManagerMock[K, V]) Delete ¶
func (m *CacheManagerMock[K, V]) Delete(ctx context.Context, keys ...K) error
func (*CacheManagerMock[K, V]) Flush ¶
func (m *CacheManagerMock[K, V]) Flush(ctx context.Context) error
func (*CacheManagerMock[K, V]) Get ¶
func (m *CacheManagerMock[K, V]) Get(ctx context.Context, key K) (V, bool)
func (*CacheManagerMock[K, V]) GetMultiple ¶
func (m *CacheManagerMock[K, V]) GetMultiple(ctx context.Context, keys []K) (map[K]V, bool)
func (*CacheManagerMock[K, V]) GetWithRefresh ¶
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
Click to show internal directories.
Click to hide internal directories.