cache

package
v0.0.0-...-4125756 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cache contains interfaces for caching data.

Index

Constants

View Source
const (
	ErrKeyInvalid   = Error("cache key is not valid")
	ErrValueInvalid = Error("cache value is invalid")
	ErrNotFound     = Error("cache value not found")
)

Cache errors.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the encoded bytes of v.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal decodes the encoded data and stores the result in the value pointed to by v

Types

type Cache

type Cache interface {
	// Get gets the data from the cache and unmarshall to the given value,
	// if the data cannot be parsed into the value, and error will be returned.
	// If the data or the cache expired, cache.ErrNotFound will be returned.
	Get(ctx context.Context, key string, value interface{}) error

	// MultiGet multiple gets to collect values from multiple keys
	// Same with Get:
	// if the data cannot be parsed into the value, and error will be returned.
	// If the data or the cache expired, cache.ErrNotFound will be returned.
	MultiGet(ctx context.Context, keys []string, value interface{}) error

	// Set sets the given data to the cache with a duration TTL.
	// if the data already exist in the cache, it will be replaced by the new value and the new duration.
	// If duration is set to Zero (0), the cache will never expire until removed by calling Delete function
	// or cache is flush.
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

	// Delete deletes data from the cache.
	// if the key doesn't exist, nil error will be return.
	Delete(ctx context.Context, key string) error
}

Cache provides a way define how we cache data.

type Error

type Error string

Error represents a cache error.

func (Error) Error

func (e Error) Error() string

Error returns the error message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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