cache

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

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

func NewMemory

func NewMemory(expiration time.Duration, cleanup time.Duration) *Memory

func (*Memory) Decrement

func (m *Memory) Decrement(ctx context.Context, key string, by int64) (int64, error)

Decrement atomically decreases the integer value stored at key by the given amount.

func (*Memory) Delete

func (m *Memory) Delete(_ context.Context, key string) error

Delete removes the cached value for the given key.

func (*Memory) Forever

func (m *Memory) Forever(_ context.Context, key string, value any) error

Forever stores a value permanently (no TTL).

func (*Memory) Get

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

Get retrieves the value for the given key.

func (*Memory) Has

func (m *Memory) Has(_ context.Context, key string) (bool, error)

Has returns true if the key exists in the cache and is not expired.

func (*Memory) Increment

func (m *Memory) Increment(ctx context.Context, key string, by int64) (int64, error)

Increment atomically increases the integer value stored at key by the given amount.

func (*Memory) Pull

func (m *Memory) Pull(ctx context.Context, key string) (any, error)

Pull retrieves and removes the value for the given key.

func (*Memory) Put

func (m *Memory) Put(_ context.Context, key string, value any, ttl time.Duration) error

Put stores a value for the given key with a TTL.

func (*Memory) Remember

func (m *Memory) Remember(ctx context.Context, key string, ttl time.Duration, compute func() (any, error)) (any, error)

Remember tries to get the value or compute and store it if not found.

func (*Memory) RememberForever

func (m *Memory) RememberForever(ctx context.Context, key string, compute func() (any, error)) (any, error)

RememberForever tries to get the value or compute and store it forever if not found.

type RedisClient

type RedisClient redis.Client

func NewRedis

func NewRedis(options *RedisOptions) *RedisClient

func NewRedisFrom added in v0.9.0

func NewRedisFrom(client *redis.Client) *RedisClient

func (*RedisClient) Decrement

func (c *RedisClient) Decrement(ctx context.Context, key string, by int64) (int64, error)

Decrement decreases a key's integer value by 'by'.

func (*RedisClient) Delete

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

Delete removes a key.

func (*RedisClient) Forever

func (c *RedisClient) Forever(ctx context.Context, key string, value any) error

Forever stores a value indefinitely.

func (*RedisClient) Get

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

Get retrieves a value by key or returns contract.ErrNotFound if missing.

func (*RedisClient) Has

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

Has checks if key exists.

func (*RedisClient) Increment

func (c *RedisClient) Increment(ctx context.Context, key string, by int64) (int64, error)

Increment increases a key's integer value by 'by'.

func (*RedisClient) Pull

func (c *RedisClient) Pull(ctx context.Context, key string) (v any, e error)

Pull retrieves and deletes a key atomically.

func (*RedisClient) Put

func (c *RedisClient) Put(ctx context.Context, key string, value any, ttl time.Duration) error

Put sets a key with value and TTL.

func (*RedisClient) Remember

func (c *RedisClient) Remember(ctx context.Context, key string, ttl time.Duration, compute func() (any, error)) (any, error)

Remember gets or computes and caches a value with TTL.

func (*RedisClient) RememberForever

func (c *RedisClient) RememberForever(ctx context.Context, key string, compute func() (any, error)) (any, error)

RememberForever caches a computed value indefinitely.

type RedisOptions

type RedisOptions = redis.Options

Jump to

Keyboard shortcuts

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