cache

package
v0.0.0-...-9a953c3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory() *Memory

func (*Memory) Get

func (c *Memory) Get(_ context.Context, key string, val any) error

func (*Memory) Has

func (c *Memory) Has(ctx context.Context, key string) (bool, error)

func (*Memory) Keys

func (c *Memory) Keys(ctx context.Context, pattern string) ([]string, error)

Keys will return the set of keys in the cache matching the given "*" based pattern. WARNING: This implementation only supports a single wildcard.

func (*Memory) Set

func (c *Memory) Set(ctx context.Context, key string, val any, ttl time.Duration) error

Set will create a cache file for the given key. TODO: Support TTL based expirations

type Redis

type Redis struct {
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(dbPrefix string) (*Redis, error)

NewRedis instantiates a new Cache client backed by Redis. This will connect to Redis based on the presence of environment variables.

If the `REDIS_USER` or `REDIS_PASSWORD` (or `REDIS_PASS`) environment variables are set, the connection will be upgraded to secure.

By default DB 0 is used, but can be configured with the `REDIS_DB` environment variable.

func NewRedisInsecure

func NewRedisInsecure(host, port string, db int, dbPrefix string) (*Redis, error)

NewRedisInsecure instantiates a new insecure client

func NewRedisSecure

func NewRedisSecure(host, port, user, password string, db int, dbPrefix string) (*Redis, error)

NewRedisSecure instantiates a new secure TLS client

func (*Redis) Get

func (c *Redis) Get(ctx context.Context, key string, val any) error

func (*Redis) Has

func (c *Redis) Has(ctx context.Context, key string) (bool, error)

func (*Redis) Keys

func (c *Redis) Keys(ctx context.Context, pattern string) ([]string, error)

func (*Redis) Set

func (c *Redis) Set(ctx context.Context, key string, val any, ttl time.Duration) error

Jump to

Keyboard shortcuts

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