cache

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Code generated by interfacer, DO NOT EDIT.

Index

Constants

View Source
const DefaultTimeout = 15 * time.Minute

Variables

View Source
var ErrNil = valkey.Nil // Exported error for nil values

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Delete removes a key from the cache.
	Delete(ctx context.Context, key string) error
	// Disconnect forcefully disconnects the cache client.
	// if `noTeardown` is true, it will not set the teardown flag,
	// allowing the client to be reused later.
	//
	// If `noTeardown` is false or not provided, it will set the teardown flag
	// and close the client connection, preventing any further operations.
	// This is useful for graceful shutdowns or when you want to ensure the client
	// is no longer usable after disconnecting.
	Disconnect(noTeardown ...bool)
	// Exists checks if a key exists.
	Exists(ctx context.Context, key string) (bool, error)
	// Get retrieves a value from the cache by its key and unmarshals it into the provided value.
	Get(ctx context.Context, key string, value any) error
	// GetWithResetTTL retrieves a value from the cache by its key, unmarshals it into the provided value,.
	GetWithResetTTL(ctx context.Context, key string, value any, ttl time.Duration) error
	// IncrBy increments the value of a key in the cache by a specified amount.
	IncrBy(ctx context.Context, key string, increment int64) (int64, error)
	// Lock locks a key in the cache for a specified duration.
	Lock(ctx context.Context, key string, timeout time.Duration) (bool, error)
	// Publish publishes a message to a channel.
	Publish(ctx context.Context, channel string, message string) error
	// Set sets a value in the cache with a specified timeout.
	Set(ctx context.Context, key string, value any, timeout time.Duration) error
	// Subscribe listens to a channel and calls the callback function for each message received.
	// Make use of a goroutine to run this function, as it will block until the context is done.
	Subscribe(channel string, callback func(msg string) error) error
	// TTL returns the time to live of a key in the cache.
	TTL(ctx context.Context, key string) (time.Duration, error)
	// Unlock unlocks a key in the cache.
	Unlock(ctx context.Context, key string) error
	// Wrapped will attempt to get the value from the cache, if it doesn't exist it will call the fallbackFunc
	// and set the value in the cache. Timeout is optional and will default to 15 minutes. 0 means no timeout.
	// -1 means no cache.
	Wrapped(ctx context.Context, key string, data any, fallbackFunc func() error, timeout ...time.Duration) error
}

Cache defines the public interface for cacheClient.

func NewCache

func NewCache(config config.CacheConfig) (Cache, error)

Jump to

Keyboard shortcuts

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