cache

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is an error report that the key is not found.
	ErrNotFound = errors.New("cache: key not found")
)

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	// Open establish connection to the target server.
	Open(ctx context.Context) error
	// Get a value, return ErrNotFound if key not found.
	Get(ctx context.Context, key string) ([]byte, error)
	// Set a value
	Set(ctx context.Context, key string, val []byte, opts ...SetOption) error
	// Delete a value
	Delete(ctx context.Context, key string) error
	// Close close the underlying connection.
	Close(ctx context.Context) error
}

Cacher is interface for a cache service.

type SetOption

type SetOption func(*SetOptions)

SetOption is option when setting value for a key.

func TTL

func TTL(ttl time.Duration) SetOption

TTL is an option to set Time To Live for a key.

type SetOptions

type SetOptions struct {
	TTL time.Duration
}

SetOptions hold options when setting value for a key.

func (*SetOptions) Apply

func (opt *SetOptions) Apply(opts ...SetOption)

Apply apply the options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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