Documentation
¶
Overview ¶
Package cache is a generated GoMock package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CacherTests = []struct { Size int Func func(t *testing.T, c Cacher[ids.ID, int]) }{ {Size: 1, Func: TestBasic}, {Size: 2, Func: TestEviction}, }
CacherTests is a list of all Cacher tests
Functions ¶
Types ¶
type Cacher ¶
type Cacher[K comparable, V any] interface { // Put inserts an element into the cache. If space is required, elements will // be evicted. Put(key K, value V) // Get returns the entry in the cache with the key specified, if no value // exists, false is returned. Get(key K) (V, bool) // Evict removes the specified entry from the cache Evict(key K) // Flush removes all entries from the cache Flush() }
Cacher acts as a best effort key value store.
type Deduplicator ¶
type Deduplicator[K comparable, V Evictable[K]] interface { // Deduplicate returns either the provided value, or a previously provided // value with the same ID that hasn't yet been evicted Deduplicate(V) V // Flush removes all entries from the cache Flush() }
Deduplicator acts as a best effort deduplication service
type Evictable ¶
type Evictable[K comparable] interface { Key() K Evict() }
Evictable allows the object to be notified when it is evicted
type EvictableLRU ¶
type EvictableLRU[K comparable, _ Evictable[K]] struct { Size int // contains filtered or unexported fields }
EvictableLRU is an LRU cache that notifies the objects when they are evicted.
func (*EvictableLRU[_, V]) Deduplicate ¶
func (c *EvictableLRU[_, V]) Deduplicate(value V) V
func (*EvictableLRU[_, _]) Flush ¶
func (c *EvictableLRU[_, _]) Flush()
type LRU ¶
type LRU[K comparable, V any] struct { // If set to < 0, will be set internally to 1. Size int // contains filtered or unexported fields }
LRU is a key value store with bounded size. If the size is attempted to be exceeded, then an element is removed from the cache before the insertion is done, based on evicting the least recently used value.
type MockCacher ¶
type MockCacher[K comparable, V any] struct { // contains filtered or unexported fields }
MockCacher is a mock of Cacher interface.
func NewMockCacher ¶
func NewMockCacher[K comparable, V any](ctrl *gomock.Controller) *MockCacher[K, V]
NewMockCacher creates a new mock instance.
func (*MockCacher[K, V]) EXPECT ¶
func (m *MockCacher[K, V]) EXPECT() *MockCacherMockRecorder[K, V]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockCacher[K, V]) Get ¶
func (m *MockCacher[K, V]) Get(arg0 K) (V, bool)
Get mocks base method.
func (*MockCacher[K, V]) Put ¶
func (m *MockCacher[K, V]) Put(arg0 K, arg1 V)
Put mocks base method.
type MockCacherMockRecorder ¶
type MockCacherMockRecorder[K comparable, V any] struct { // contains filtered or unexported fields }
MockCacherMockRecorder is the mock recorder for MockCacher.
func (*MockCacherMockRecorder[K, V]) Evict ¶
func (mr *MockCacherMockRecorder[K, V]) Evict(arg0 interface{}) *gomock.Call
Evict indicates an expected call of Evict.
func (*MockCacherMockRecorder[K, V]) Flush ¶
func (mr *MockCacherMockRecorder[K, V]) Flush() *gomock.Call
Flush indicates an expected call of Flush.
func (*MockCacherMockRecorder[K, V]) Get ¶
func (mr *MockCacherMockRecorder[K, V]) Get(arg0 interface{}) *gomock.Call
Get indicates an expected call of Get.
func (*MockCacherMockRecorder[K, V]) Put ¶
func (mr *MockCacherMockRecorder[K, V]) Put(arg0, arg1 interface{}) *gomock.Call
Put indicates an expected call of Put.