Documentation ¶
Index ¶
- type MemReadThroughCache
- func (m *MemReadThroughCache) Contains(id string) bool
- func (m *MemReadThroughCache) Get(ctx context.Context, id string) (interface{}, error)
- func (m *MemReadThroughCache) GetAll(ctx context.Context, ids []string) ([]interface{}, error)
- func (m *MemReadThroughCache) Keys() []string
- func (m *MemReadThroughCache) Len() int
- func (m *MemReadThroughCache) Remove(ids []string)
- type ReadThroughCache
- type ReadThroughFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemReadThroughCache ¶
type MemReadThroughCache struct {
// contains filtered or unexported fields
}
MemReadThroughCache implements the ReadThroughCache interface.
func New ¶
func New(rtf ReadThroughFunc, maxCachedItems int, maxConcurrentReadThroughCalls int) (*MemReadThroughCache, error)
New returns a new instance of ReadThroughCache that is stored in RAM. maxConcurrentReadThroughCalls defines the number of concurrent calls to the ReadThroughFunc when requested items are not cached.
func (*MemReadThroughCache) Contains ¶
func (m *MemReadThroughCache) Contains(id string) bool
Contains implements the ReadThroughCache interface.
func (*MemReadThroughCache) Get ¶
func (m *MemReadThroughCache) Get(ctx context.Context, id string) (interface{}, error)
Get implements the ReadThroughCache interface.
func (*MemReadThroughCache) GetAll ¶
func (m *MemReadThroughCache) GetAll(ctx context.Context, ids []string) ([]interface{}, error)
GetAll implements the ReadThroughCache interface.
func (*MemReadThroughCache) Keys ¶
func (m *MemReadThroughCache) Keys() []string
Keys implements the ReadThroughCache interface.
func (*MemReadThroughCache) Len ¶
func (m *MemReadThroughCache) Len() int
Len implements the ReadThroughCache interface.
func (*MemReadThroughCache) Remove ¶
func (m *MemReadThroughCache) Remove(ids []string)
Remove implements the ReadThroughCache interface.
type ReadThroughCache ¶
type ReadThroughCache interface { // Get returns the item identified by 'id' or an error if the item // cannot be retrieved. If the item is not in the cache a worker function // is called to retrieve it. Get(ctx context.Context, id string) (interface{}, error) // GetAll returns all items identified by 'ids' or an error if any of them // cannot be retrieved. If any items are not in the cache, a worker function // is called per item to retrieve them. GetAll(ctx context.Context, ids []string) ([]interface{}, error) // Len returns the number of items that are cached. Len() int // Keys returns the keys of the items that are cached. Keys() []string // Contains returns true if the identified item is currently cached. Contains(id string) bool // Remove removes the element with the given ids from the cache. Remove(ids []string) }
ReadThroughCache defines a caching work queue with priorities. If the item identified by 'id' is not in the cache then it will call a provided ReadThroughFunc in order to calculate it.