Documentation
¶
Index ¶
Constants ¶
const (
NoTTL = -1
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expired ¶
Expired is a special type of error indicating that a key is no longer valid (value is still attached in the error)
type MLCLayer ¶
type MLCLayer[K comparable, V comparable] interface { Get(ctx context.Context, key K) (V, error) Set(ctx context.Context, key K, value V) error }
MLCLayer is the interface that should be implemented for all caching structs to be used with this piece of code.
type Miss ¶
type Miss struct {
Where string
Key interface{}
}
Miss is a special type of error indicating that a key was not found
type MultiLevelCache ¶
type MultiLevelCache[K comparable, V comparable] interface { Get(ctx context.Context, key K) (V, error) }
MultiLevelCache bundles a list of ordered cache layers (upper -> lower)
type MultiLevelCacheImpl ¶
type MultiLevelCacheImpl[K comparable, V comparable] struct { // contains filtered or unexported fields }
MultiLevelCacheImpl implements the MultiLevelCache interface
func NewMultiLevel ¶
func NewMultiLevel[K comparable, V comparable](layers []MLCLayer[K, V], logger logging.LoggerInterface) (*MultiLevelCacheImpl[K, V], error)
NewMultiLevel creates and returns a new MultiLevelCache instance
type SimpleLRU ¶
type SimpleLRU[K comparable, V any] interface { Get(key K) (V, error) Set(key K, value V) error FlushKey(key K) }
SimpleLRU is an in-memory TTL & LRU cache
type SimpleLRUImpl ¶
type SimpleLRUImpl[K comparable, V any] struct { // contains filtered or unexported fields }
SimpleLRUImpl implements the Simple interface
func NewSimpleLRU ¶
func NewSimpleLRU[K comparable, V any](maxSize int, ttl time.Duration) (*SimpleLRUImpl[K, V], error)
NewSimple returns a new Simple instance of the specified size and TTL
func (*SimpleLRUImpl[K, V]) FlushKey ¶
func (c *SimpleLRUImpl[K, V]) FlushKey(key K)
FlushKey removes an entry form the cache if it exists. Does nothing otherwise
func (*SimpleLRUImpl[K, V]) Get ¶
func (c *SimpleLRUImpl[K, V]) Get(key K) (V, error)
Get retrieves an item if exist, nil + an error otherwise
func (*SimpleLRUImpl[K, V]) Set ¶
func (c *SimpleLRUImpl[K, V]) Set(key K, value V) error
Set adds a new item. Since the cache being full results in removing the LRU element, this method never fails.