Documentation
¶
Index ¶
- Variables
- type Collection
- type ErrConflictGeneration
- type ErrMaxElementsExceeded
- type GenericStore
- func (s *GenericStore[T, H]) Delete(ctx context.Context, id string) error
- func (s *GenericStore[T, H]) Get(ctx context.Context) (*Collection[T], error)
- func (s *GenericStore[T, H]) Read(ctx context.Context, txn ReadTxn[T]) error
- func (s *GenericStore[T, H]) Update(ctx context.Context, txn UpdateTxn[T]) error
- func (s *GenericStore[T, H]) Upsert(ctx context.Context, elem T, observedGeneration *int64, maxElements int) error
- type Key
- type ReadTxn
- type StoreHelper
- type UpdateTxn
Constants ¶
This section is empty.
Variables ¶
var ErrElementNotFound = errors.New("element not found")
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type ErrConflictGeneration ¶
func (ErrConflictGeneration) Error ¶
func (e ErrConflictGeneration) Error() string
type ErrMaxElementsExceeded ¶ added in v2.1.0
type ErrMaxElementsExceeded struct {
Max int
}
ErrMaxElementsExceeded is returned by Upsert when inserting a new element would exceed the configured maximum number of elements in the collection.
func (ErrMaxElementsExceeded) Error ¶ added in v2.1.0
func (e ErrMaxElementsExceeded) Error() string
type GenericStore ¶
type GenericStore[T any, H StoreHelper[T]] struct { // contains filtered or unexported fields }
func New ¶
func New[T any, H StoreHelper[T]]( logger log.Logger, bucket objstore.Bucket, key Key, helper H, ) *GenericStore[T, H]
func (*GenericStore[T, H]) Delete ¶
func (s *GenericStore[T, H]) Delete(ctx context.Context, id string) error
func (*GenericStore[T, H]) Get ¶
func (s *GenericStore[T, H]) Get(ctx context.Context) (*Collection[T], error)
func (*GenericStore[T, H]) Read ¶
func (s *GenericStore[T, H]) Read(ctx context.Context, txn ReadTxn[T]) error
func (*GenericStore[T, H]) Update ¶
func (s *GenericStore[T, H]) Update( ctx context.Context, txn UpdateTxn[T], ) error
Update will under write lock, call a transaction the Collection. If there is an error returned, the update will be cancelled.
func (*GenericStore[T, H]) Upsert ¶
func (s *GenericStore[T, H]) Upsert(ctx context.Context, elem T, observedGeneration *int64, maxElements int) error
Upsert inserts or updates elem in the collection. If maxElements is greater than 0, inserting a new element is rejected with ErrMaxElementsExceeded once the collection already holds maxElements elements. Updates to an existing element are never affected by maxElements. The check runs inside the write transaction, so the limit is enforced atomically against concurrent upserts.
type ReadTxn ¶
type ReadTxn[T any] func(context.Context, *Collection[T]) error
ReadTxn is a transaction that runs under the read lock of the cache. The Collection should not be mutated at all.