Documentation ¶
Overview ¶
Package lrustore provides a datastore wrapper that limits the number of items stored to the specified capacity. When at capacity, the oldest items are removed in LRU to make root for new items. Putting and getting items maintains LRU order.
Index ¶
- type LRUStore
- func (ls *LRUStore) Batch(ctx context.Context) (ds.Batch, error)
- func (ls *LRUStore) Cap() int
- func (ls *LRUStore) Clear(ctx context.Context) error
- func (ls *LRUStore) Close() error
- func (ls *LRUStore) Delete(ctx context.Context, key ds.Key) error
- func (ls *LRUStore) DiskUsage(ctx context.Context) (uint64, error)
- func (ls *LRUStore) Get(ctx context.Context, key ds.Key) ([]byte, error)
- func (ls *LRUStore) GetSize(ctx context.Context, key ds.Key) (int, error)
- func (ls *LRUStore) Has(ctx context.Context, key ds.Key) (bool, error)
- func (ls *LRUStore) Len() int
- func (ls *LRUStore) Put(ctx context.Context, key ds.Key, val []byte) error
- func (ls *LRUStore) Query(ctx context.Context, q dsq.Query) (dsq.Results, error)
- func (ls *LRUStore) Resize(ctx context.Context, newSize int) (int, error)
- func (ls *LRUStore) Sync(ctx context.Context, key ds.Key) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRUStore ¶
type LRUStore struct {
// contains filtered or unexported fields
}
LRUStore is a LRU-cache that stores keys in memory and values in a datastore.
func New ¶
New creates a new LRUStore instance. The context is only used cancel a call to this function while it is accessing the data store.
func (*LRUStore) Cap ¶
Cap returns the LRUStore capacity. Storing more than this number of items results in discarding oldest items.
func (*LRUStore) Close ¶
Close syncs the LRUStore entries but does not close the underlying datastore. This is because LRUStore wraps an existing datastore and does not construct it, and the wrapped datastore may be in use elsewhere.
func (*LRUStore) Has ¶
Has implements datastore interface. Has determines if the item is present in the LRUStore without moving the item to the newest LRU position.