cache

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheMiss = errors.New("cache miss")
	ErrCacheFull = errors.New("cache full")
	ErrKeyType   = errors.New("invalid key type")
)

Functions

func AddToSet added in v0.0.5

func AddToSet(ctx context.Context, key string, member string) error

AddToSet is wrapper for global cache.AddToSet.

func Close

func Close(ctx context.Context) error

Close is wrapper for global cache.Close.

func Delete

func Delete(ctx context.Context, key string) error

Delete is wrapper for global cache.Delete.

func DeleteFromHash added in v0.0.5

func DeleteFromHash(ctx context.Context, key string, field string) error

DeleteFromHash is wrapper for global cache.DeleteFromHash.

func DeleteFromSet added in v0.0.5

func DeleteFromSet(ctx context.Context, key string, member string) error

DeleteFromSet is wrapper for global cache.DeleteFromSet.

func Get

func Get(ctx context.Context, key string) ([]byte, error)

Get is wrapper for global cache.Get.

func GetFromHash added in v0.0.5

func GetFromHash(ctx context.Context, key string, field string) ([]byte, error)

GetFromHash is wrapper for global cache.GetFromHash.

func IsInSet added in v0.0.5

func IsInSet(ctx context.Context, key string, member string) (bool, error)

IsInSet is wrapper for global cache.IsInSet.

func Set

func Set(ctx context.Context, key string, value []byte, expire time.Duration) error

Set is wrapper for global cache.Set.

func SetGlobalCache

func SetGlobalCache(c Cache)

SetGlobalCache sets the global cache.

func SetToHash added in v0.0.5

func SetToHash(ctx context.Context, key string, field string, value []byte) error

SetToHash is wrapper for global cache.SetToHash.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, expire time.Duration) error
	Delete(ctx context.Context, key string) error

	IsInSet(ctx context.Context, key string, member string) (bool, error)
	AddToSet(ctx context.Context, key string, member string) error
	DeleteFromSet(ctx context.Context, key string, member string) error

	GetFromHash(ctx context.Context, key string, field string) ([]byte, error)
	SetToHash(ctx context.Context, key string, field string, value []byte) error
	DeleteFromHash(ctx context.Context, key string, field string) error

	Close(ctx context.Context) error
}

func GetGlobalCache

func GetGlobalCache() Cache

GetGlobalCache returns the global cache.

func NewMemoryCache

func NewMemoryCache() Cache

func NewRedisCache

func NewRedisCache(cli *redisv8.Client) Cache

NewRedisCache creates a new redisCache instance.

Jump to

Keyboard shortcuts

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