cache

package
v0.107.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntityRepository added in v0.82.0

type EntityRepository[Entity, ID any] interface {
	crud.Creator[Entity]
	crud.Updater[Entity]
	crud.Finder[Entity, ID]
	crud.Deleter[ID]
	FindByIDs(ctx context.Context, ids ...ID) iterators.Iterator[Entity]
	Upsert(ctx context.Context, ptrs ...*Entity) error
}

type ExtendedSource

type ExtendedSource[Entity, ID any] interface {
	crud.Updater[Entity]
	pubsub.UpdaterPublisher[Entity]
}

type Hit

type Hit[ID any] struct {
	QueryID   string `ext:"id"`
	EntityIDs []ID
}

type HitRepository added in v0.82.0

type HitRepository[EntID any] interface {
	crud.Creator[Hit[EntID]]
	crud.Updater[Hit[EntID]]
	crud.Finder[Hit[EntID], string]
	crud.Deleter[string]
}

HitRepository is the query hit result repository.

type Manager

type Manager[Entity, ID any] struct {
	// Source is the location of the original data
	Source Source[Entity, ID]
	// Repository is the resource that keeps the cached data.
	Repository Repository[Entity, ID]
	// contains filtered or unexported fields
}

func NewManager

func NewManager[Entity, ID any](repository Repository[Entity, ID], source Source[Entity, ID]) (*Manager[Entity, ID], error)

func (*Manager[Entity, ID]) CacheQueryMany

func (m *Manager[Entity, ID]) CacheQueryMany(
	ctx context.Context,
	name string,
	query func() iterators.Iterator[Entity],
) iterators.Iterator[Entity]

func (*Manager[Entity, ID]) CacheQueryOne

func (m *Manager[Entity, ID]) CacheQueryOne(
	ctx context.Context,
	queryID string,
	query func() (ent Entity, found bool, err error),
) (_ent Entity, _found bool, _err error)

func (*Manager[Entity, ID]) Close

func (m *Manager[Entity, ID]) Close() error

func (*Manager[Entity, ID]) Create

func (m *Manager[Entity, ID]) Create(ctx context.Context, ptr *Entity) error

func (*Manager[Entity, ID]) DeleteAll

func (m *Manager[Entity, ID]) DeleteAll(ctx context.Context) error

func (*Manager[Entity, ID]) DeleteByID

func (m *Manager[Entity, ID]) DeleteByID(ctx context.Context, id ID) error

func (*Manager[Entity, ID]) FindAll

func (m *Manager[Entity, ID]) FindAll(ctx context.Context) iterators.Iterator[Entity]

func (*Manager[Entity, ID]) FindByID

func (m *Manager[Entity, ID]) FindByID(ctx context.Context, id ID) (Entity, bool, error)

func (*Manager[Entity, ID]) Init

func (m *Manager[Entity, ID]) Init(ctx context.Context) error

func (*Manager[Entity, ID]) SubscribeToCreatorEvents

func (m *Manager[Entity, ID]) SubscribeToCreatorEvents(ctx context.Context, creatorSubscriber pubsub.CreatorSubscriber[Entity]) (pubsub.Subscription, error)

func (*Manager[Entity, ID]) SubscribeToDeleterEvents

func (m *Manager[Entity, ID]) SubscribeToDeleterEvents(ctx context.Context, s pubsub.DeleterSubscriber[ID]) (pubsub.Subscription, error)

func (*Manager[Entity, ID]) SubscribeToUpdaterEvents

func (m *Manager[Entity, ID]) SubscribeToUpdaterEvents(ctx context.Context, s pubsub.UpdaterSubscriber[Entity]) (pubsub.Subscription, error)

func (*Manager[Entity, ID]) Update

func (m *Manager[Entity, ID]) Update(ctx context.Context, ptr *Entity) error

type Repository added in v0.82.0

type Repository[Entity, ID any] interface {
	CacheEntity(ctx context.Context) EntityRepository[Entity, ID]
	CacheHit(ctx context.Context) HitRepository[ID]
	comproto.OnePhaseCommitProtocol
}

type Source

type Source[Entity, ID any] interface {
	crud.Creator[Entity]
	crud.Finder[Entity, ID]
	crud.Deleter[ID]
	pubsub.CreatorPublisher[Entity]
	pubsub.DeleterPublisher[ID]
}

Source is the minimum expected interface that is expected from a Source resources that needs caching. On top of this, cache.Manager also supports Updater, CreatorPublisher, UpdaterPublisher and DeleterPublisher.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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