cache

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 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 EntityStorage

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

type ExtendedSource

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

type Hit

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

type HitStorage

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

HitStorage is the query hit result storage.

type Manager

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

func NewManager

func NewManager[Ent, ID any](storage Storage[Ent, ID], source Source[Ent, ID]) (*Manager[Ent, ID], error)

func (*Manager[Ent, ID]) CacheQueryMany

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

func (*Manager[Ent, ID]) CacheQueryOne

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

func (*Manager[Ent, ID]) Close

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

func (*Manager[Ent, ID]) Create

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

func (*Manager[Ent, ID]) DeleteAll

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

func (*Manager[Ent, ID]) DeleteByID

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

func (*Manager[Ent, ID]) FindAll

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

func (*Manager[Ent, ID]) FindByID

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

func (*Manager[Ent, ID]) Init

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

func (*Manager[Ent, ID]) SubscribeToCreatorEvents

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

func (*Manager[Ent, ID]) SubscribeToDeleterEvents

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

func (*Manager[Ent, ID]) SubscribeToUpdaterEvents

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

func (*Manager[Ent, ID]) Update

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

type Source

type Source[Ent, ID any] interface {
	crud.Creator[Ent]
	crud.Finder[Ent, ID]
	crud.Deleter[ID]
	pubsub.CreatorPublisher[Ent]
	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.

type Storage

type Storage[Ent, ID any] interface {
	CacheEntity(ctx context.Context) EntityStorage[Ent, ID]
	CacheHit(ctx context.Context) HitStorage[ID]
	comproto.OnePhaseCommitProtocol
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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