Documentation ¶
Overview ¶
Package cache will supply caching solutions for your crud port compatible resources.
Index ¶
- Constants
- type Cache
- func (m *Cache[Entity, ID]) CachedQueryMany(ctx context.Context, queryKey string, query QueryManyFunc[Entity]) iterators.Iterator[Entity]
- func (m *Cache[Entity, ID]) CachedQueryOne(ctx context.Context, queryKey string, query QueryOneFunc[Entity]) (_ent Entity, _found bool, _err error)
- func (m *Cache[Entity, ID]) Create(ctx context.Context, ptr *Entity) error
- func (m *Cache[Entity, ID]) DeleteAll(ctx context.Context) error
- func (m *Cache[Entity, ID]) DeleteByID(ctx context.Context, id ID) (rErr error)
- func (m *Cache[Entity, ID]) DropCachedValues(ctx context.Context) error
- func (m *Cache[Entity, ID]) FindAll(ctx context.Context) iterators.Iterator[Entity]
- func (m *Cache[Entity, ID]) FindByID(ctx context.Context, id ID) (Entity, bool, error)
- func (m *Cache[Entity, ID]) InvalidateByID(ctx context.Context, id ID) (rErr error)
- func (m *Cache[Entity, ID]) Update(ctx context.Context, ptr *Entity) error
- type EntityRepository
- type Hit
- type HitID
- type HitRepository
- type Interface
- type QueryKey
- type QueryManyFunc
- type QueryOneFunc
- type Repository
- type Source
Constants ¶
View Source
const ErrNotImplementedBySource errorkit.Error = "the method is not implemented by the cache source"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[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] }
Cache supplies Read/Write-Through caching to CRUD resources.
func New ¶
func New[Entity, ID any]( source Source[Entity, ID], cacheRepo Repository[Entity, ID], ) *Cache[Entity, ID]
func (*Cache[Entity, ID]) CachedQueryMany ¶ added in v0.126.0
func (*Cache[Entity, ID]) CachedQueryOne ¶ added in v0.126.0
func (*Cache[Entity, ID]) DeleteByID ¶
func (*Cache[Entity, ID]) DropCachedValues ¶
func (*Cache[Entity, ID]) InvalidateByID ¶
type EntityRepository ¶
type HitRepository ¶
type HitRepository[EntID any] interface { crud.Creator[Hit[EntID]] crud.Updater[Hit[EntID]] crud.Finder[Hit[EntID], HitID] crud.Deleter[HitID] }
HitRepository is the query hit result repository.
type Interface ¶ added in v0.126.0
type Interface[Entity, ID any] interface { CachedQueryOne(ctx context.Context, queryKey string, query QueryOneFunc[Entity]) (_ent Entity, _found bool, _err error) CachedQueryMany(ctx context.Context, queryKey string, query QueryManyFunc[Entity]) iterators.Iterator[Entity] InvalidateByID(ctx context.Context, id ID) (rErr error) DropCachedValues(ctx context.Context) error }
type QueryKey ¶ added in v0.126.0
type QueryKey struct { // ID is the unique identifier to know what query is being cached. // A method name or any unique name could work. ID string // ARGS contain parameters to the query that can affect the query result. // Supplying the ARGS ensures that a query call with different arguments cached individually. ARGS map[string]any Version int }
QueryKey is a helper function that allows you to create QueryManyFunc Keys
type QueryManyFunc ¶ added in v0.126.0
type QueryOneFunc ¶ added in v0.126.0
type Repository ¶
type Repository[Entity, ID any] interface { Entities() EntityRepository[Entity, ID] Hits() HitRepository[ID] comproto.OnePhaseCommitProtocol }
type Source ¶
type Source[Entity, ID any] interface { crud.ByIDFinder[Entity, ID] }
Source is the minimum expected interface that is expected from a Source resources that needs caching. On top of this, cache.Cache also supports Updater, CreatorPublisher, UpdaterPublisher and DeleterPublisher.
Click to show internal directories.
Click to hide internal directories.