cache

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 4 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client[Entity any] interface {
	// Get returns an entity and an error.
	Get(context.Context, string) (Entity, *i18np.Error)

	// Set sets an entity and returns an error.
	Handler(Handler[Entity]) Client[Entity]

	// Set sets an entity and returns an error.
	Creator(creator Creator[Entity]) Client[Entity]

	// Set sets an entity and returns an error.
	Timeout(time.Duration) Client[Entity]
}

Client is an interface that defines the methods of a cache client

func New

func New[Entity any](service Service) Client[Entity]

New returns a new cache client It receives a service that implements the Service interface and returns a Client interface

type Creator

type Creator[Entity any] func() Entity // Creator is a function that returns an entity. It's running when the entity is found in the cache and make a pointer to it

type Handler

type Handler[Entity any] func() (Entity, *i18np.Error) // Handler is a function that returns an entity and an error. It's running when the entity is not found in the cache

type Service

type Service interface {
	// Get returns a value and an error.
	Get(ctx context.Context, k string) (string, error)

	// Set sets a value and returns an error.
	SetEx(ctx context.Context, k string, v interface{}, d time.Duration) error

	// Set sets a value and returns an error.
	Exist(ctx context.Context, k string) (bool, error)
}

Service is an interface that defines the methods of a cache service It's implemented by the cache service

Jump to

Keyboard shortcuts

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