cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value string, expiration time.Duration) error
	Get(ctx context.Context, key string) (string, error)

	SetStruct(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	GetStruct(ctx context.Context, key string, targetRef interface{}) (interface{}, error)
	Delete(ctx context.Context, key string) error
}

Cache interface specifies the methods of the cache system. Allows us to use either in-memory or Redis.

func NewClient

func NewClient(options Options) Cache

func NewInMemory

func NewInMemory() Cache

type Connection

type Connection struct {
	Client  *redis.Client
	Options Options
}

func (*Connection) Delete

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

Delete executes the redis Del command

func (*Connection) Get

func (c *Connection) Get(ctx context.Context, key string) (string, error)

Get executes the redis Get command

func (*Connection) GetStruct

func (c *Connection) GetStruct(ctx context.Context, key string, target interface{}) (interface{}, error)

GetStruct executes the redis Get command

func (*Connection) Ping

func (connection *Connection) Ping(ctx context.Context) error

Ping tests connectivity for redis (PONG should be returned)

func (*Connection) Set

func (c *Connection) Set(ctx context.Context, key string, value string, expiration time.Duration) error

Set executes the redis Set command

func (*Connection) SetStruct

func (c *Connection) SetStruct(ctx context.Context, key string, value interface{}, expiration time.Duration) error

SetStruct executes the redis Set command

type Options

type Options struct {
	Address                  string
	Password                 string
	DB                       int
	DefaultDurationInSeconds int
}

func DefaultOptions

func DefaultOptions() Options

func (*Options) GetDefaultDuration

func (opt *Options) GetDefaultDuration() time.Duration

Jump to

Keyboard shortcuts

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