cachedrepository

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheActionCause

type CacheActionCause int64
const (
	CacheActionCauseRepositoryAction CacheActionCause = iota
	CacheActionCauseReconciliation
)

type CachedRepository

type CachedRepository[BaseEntity any, ProcessedEntity any, ChangeContext any] struct {
	// contains filtered or unexported fields
}

func NewCachedRepository

func NewCachedRepository[BaseEntity any, ProcessedEntity any, ChangeContext any](
	key string,
	repository Repository[BaseEntity, ChangeContext],
	cache cache.Cache[ProcessedEntity],
	processor Processor[BaseEntity, ProcessedEntity],
	locker locker.Locker,
	hooks Hooks[ProcessedEntity],
) *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Create

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Create(
	ctx context.Context,
	name string,
	entity BaseEntity,
	changeContext *ChangeContext,
) error

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Delete

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Delete(
	ctx context.Context,
	name string,
	changeContext *ChangeContext,
) error

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Read

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Read(
	ctx context.Context,
	name string,
) (ProcessedEntity, string, error)

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) ReadAll

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) ReadAll(
	ctx context.Context,
) (map[string]ProcessedEntity, error)

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Reconcile

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Reconcile(
	ctx context.Context,
	name string,
) error

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) ReconcileAll

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) ReconcileAll(
	ctx context.Context,
) error

func (*CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Update

func (c *CachedRepository[BaseEntity, ProcessedEntity, ChangeContext]) Update(
	ctx context.Context,
	name string,
	entity BaseEntity,
	modifyIfMatchHash string,
	changeContext *ChangeContext,
) error

type CustomCompare

type CustomCompare interface {
	IsEqual(other any) (bool, error)
}

ToDo: Use later for custom compare

type CustomHash

type CustomHash interface {
	Hash() (string, error)
}

ToDo: Use later for custom hash

type ErrHashMismatch

type ErrHashMismatch struct {
	// contains filtered or unexported fields
}

func NewErrHashMismatch

func NewErrHashMismatch(
	providedHash string,
	actualHash string,
) ErrHashMismatch

func (ErrHashMismatch) Error

func (e ErrHashMismatch) Error() string

type ErrRepositoryEntityNotFound

type ErrRepositoryEntityNotFound struct {
	// contains filtered or unexported fields
}

func NewErrRepositoryEntityNotFound

func NewErrRepositoryEntityNotFound(name string) ErrRepositoryEntityNotFound

func (ErrRepositoryEntityNotFound) Error

type Hooks

type Hooks[Entity any] interface {
	OnRepositoryEntityCreated(
		ctx context.Context,
		name string,
		entity Entity,
	) error

	OnRepositoryEntityUpdated(
		ctx context.Context,
		name string,
		entity Entity,
	) error

	OnRepositoryEntityDeleted(
		ctx context.Context,
		name string,
	) error

	OnCacheEntityAdded(
		ctx context.Context,
		name string,
		entity Entity,
		cause CacheActionCause,
	) error

	OnCacheEntityUpdated(
		ctx context.Context,
		name string,
		entity Entity,
		cause CacheActionCause,
	) error

	OnCacheEntityRemoved(
		ctx context.Context,
		name string,
		cause CacheActionCause,
	) error
}

type Processor

type Processor[BaseEntity any, ProcessedEntity any] interface {
	ProcessEntity(
		ctx context.Context,
		entity BaseEntity,
	) (ProcessedEntity, error)

	InverseProcessEntity(
		ctx context.Context,
		entity ProcessedEntity,
	) (BaseEntity, error)
}

func NewNoProcessor

func NewNoProcessor[BaseEntity any]() Processor[BaseEntity, BaseEntity]

type Repository

type Repository[Entity any, ChangeContext any] interface {
	Create(
		ctx context.Context,
		name string,
		entity Entity,
		changeContext *ChangeContext,
	) error

	ReadAll(
		ctx context.Context,
	) (map[string]Entity, error)

	Read(
		ctx context.Context,
		name string,
	) (Entity, error)

	Update(
		ctx context.Context,
		name string,
		entity Entity,
		changeContext *ChangeContext,
	) error

	Delete(
		ctx context.Context,
		name string,
		changeContext *ChangeContext,
	) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL