Documentation
¶
Overview ¶
Package cache provides a generic caching mechanism with indexing capabilities.
Index ¶
- type Cache
- func (c *Cache[T]) Add(obj T) error
- func (c *Cache[T]) AddIndexers(newIndexers port.Indexers[T]) error
- func (c *Cache[T]) ByIndex(indexName, indexedValue string) ([]T, error)
- func (c *Cache[T]) Delete(obj T) error
- func (c *Cache[T]) Get(obj T) (item *T, exists bool, err error)
- func (c *Cache[T]) GetByKey(key string) (item *T, exists bool, err error)
- func (c *Cache[T]) GetIndexers() port.Indexers[T]
- func (c *Cache[T]) Index(indexName string, obj T) ([]any, error)
- func (c *Cache[T]) IndexKeys(indexName, indexedValue string) ([]string, error)
- func (c *Cache[T]) List() []T
- func (c *Cache[T]) ListIndexFuncValues(indexName string) []string
- func (c *Cache[T]) ListKeys() []string
- func (c *Cache[T]) Replace(list []T, resourceVersion string) error
- func (c *Cache[T]) Update(obj T) error
- type IndexNotFoundError
- type IndexerConflictError
- type ItemStore
- type KeyError
- type KeyFunc
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache is a generic struct that provides caching functionality for objects of type T.
func NewIndexer ¶
NewIndexer creates a new instance of Cache with the provided storage and key function.
func (*Cache[T]) AddIndexers ¶
AddIndexers adds new indexers to the cache.
func (*Cache[T]) ByIndex ¶
ByIndex retrieves all items that match the given indexed value for a specific index function.
func (*Cache[T]) GetIndexers ¶
GetIndexers returns the indexers used by the cache.
func (*Cache[T]) IndexKeys ¶
IndexKeys lists all keys that match the given indexed value for a specific index function.
func (*Cache[T]) List ¶
func (c *Cache[T]) List() []T
List returns a list of all items in the cache.
func (*Cache[T]) ListIndexFuncValues ¶
ListIndexFuncValues lists all indexed values for a given index function.
type IndexNotFoundError ¶
type IndexNotFoundError struct {
IndexName string
}
IndexNotFoundError indicates that the requested index does not exist.
func (IndexNotFoundError) Error ¶
func (e IndexNotFoundError) Error() string
Error implements the error interface.
type IndexerConflictError ¶
type IndexerConflictError struct {
IndexNames []string
}
IndexerConflictError indicates that one or more indexers being added already exist.
func (IndexerConflictError) Error ¶
func (e IndexerConflictError) Error() string
Error implements the error interface.
type ItemStore ¶
type ItemStore[T any] interface { Get(key string) *T Set(key string, obj T) Delete(key string) Values() []T Keys() []string }
ItemStore is a simple key-value store for items of type T.
type KeyError ¶
KeyError represents an error that occurred while generating a key for an object of type T.
type KeyFunc ¶
KeyFunc is a function that takes an object of type T and returns a string key and an error if any.
type Storage ¶
type Storage[T any] interface { Add(key string, obj T) Update(key string, obj T) Delete(key string) Get(key string) (item *T, exists bool) List() []T ListKeys() []string Replace(list map[string]T, resourceVersion string) Index(indexName string, obj T) ([]interface{}, error) IndexKeys(indexName, indexedValue string) ([]string, error) ListIndexFuncValues(name string) []string ByIndex(indexName, indexedValue string) ([]T, error) GetIndexers() port.Indexers[T] // AddIndexers adds more indexers to this store. This supports adding indexes after the store already has items. AddIndexers(newIndexers port.Indexers[T]) error }
Storage is a generic interface for a storage backend that supports basic CRUD operations and indexing.