Documentation ¶
Index ¶
Constants ¶
This section is empty.
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 Layer ¶
type Layer interface { Get(key string) (interface{}, error) Set(key string, value interface{}) error }
Layer is the interface that should be implemented for all caching structs to be used with this piece of code.
type LocalCache ¶
type LocalCache interface { Get(key string) (interface{}, error) Set(key string, value interface{}) error }
LocalCache is an in-memory TTL & LRU cache
type LocalCacheImpl ¶
type LocalCacheImpl struct {
// contains filtered or unexported fields
}
LocalCacheImpl implements the LocalCache interface
func NewLocalCache ¶
func NewLocalCache(maxSize int, ttl time.Duration) (*LocalCacheImpl, error)
NewLocalCache returns a new LocalCache instance of the specified size and TTL
func (*LocalCacheImpl) Get ¶
func (c *LocalCacheImpl) Get(key string) (interface{}, error)
Get retrieves an item if exist, nil + an error otherwise
func (*LocalCacheImpl) Set ¶
func (c *LocalCacheImpl) Set(key string, value interface{}) error
Set adds a new item. Since the cache being full results in removing the LRU element, this method never fails.
type MultiLevelCache ¶
MultiLevelCache bundles a list of ordered cache layers (upper -> lower)
type MultiLevelCacheImpl ¶
type MultiLevelCacheImpl struct {
// contains filtered or unexported fields
}
MultiLevelCacheImpl implements the MultiLevelCache interface
func NewMultiLevel ¶
func NewMultiLevel(layers []Layer, logger logging.LoggerInterface) (*MultiLevelCacheImpl, error)
NewMultiLevel creates and returns a new MultiLevelCache instance
func (*MultiLevelCacheImpl) Get ¶
func (c *MultiLevelCacheImpl) Get(key string) (interface{}, error)
Get returns the value of the requested key (if found) and populates upper levels with it