cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cache contains abstractions and implementations for a cache backend.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when an key is not found.
	ErrNotFound = errors.New("key not found")
)

Functions

func Register

func Register(scheme string, factory Factory)

Register registers a new backend by scheme. It will panic if multiple backends are registered under the same scheme.

func ValidateKey

func ValidateKey(key string) error

ValidateKey returns an error if key is invalid.

Types

type Backend

type Backend interface {
	// Ping returns an error if offline.
	Ping(context.Context) error

	// Begin starts a new Transation.
	Begin(context.Context) (Transaction, error)

	// Close closes the backend.
	Close() error
}

Backend defines the abstract backend.

func Connect

func Connect(ctx context.Context, urlString string, hlp *riposo.Helpers) (Backend, error)

Connect connects a backend via URL.

type Factory

type Factory func(context.Context, *url.URL, *riposo.Helpers) (Backend, error)

Factory initializes a new backend at runtime.

type Transaction

type Transaction interface {
	// Commit commits the transaction.
	Commit() error
	// Rollback aborts the transaction.
	Rollback() error

	// Flush deletes all stored data.
	Flush() error

	// Get retrieves a key. May return ErrNotFound.
	Get(key string) ([]byte, error)
	// Set sets a value for key.
	Set(key string, val []byte, exp time.Time) error
	// Del deletes a key. May return ErrNotFound.
	Del(key string) error
}

Transaction is a transaction.

Jump to

Keyboard shortcuts

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