cache

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Client

type Client struct {
	// GetAPI is any cache client that can get items from the cache.
	GetAPI IGet
	// SetAPI is any cache client that can set items
	SetAPI ISet
}

Client is a generic client structure for caches. All caches must fullfil the APIs that Client provides. Client is structured in this way to allow for easy extension of the cache package as well as ease of mocking.

func (*Client) Get

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

Get simply gets an item from the cache based on the API provided by the cache client.

func (*Client) Set

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

Set simply sets an item in the cache based on the API provided by the cache client.

type ClientAPIs

type ClientAPIs interface {
	// IGet is an interface for all cache clients that support Get operations.
	IGet
	// ISet is an interface for all cache clients that support Set operations.
	ISet
}

ClientAPIs consolidates the APIs that a custom cache client must implement.

type Config

type Config struct {
	// CacheProvider is the type of cache to use. These are constants in the cache package.
	CacheProvider constants.CacheType
	// CustomConfiguration is a configuration for a custom cache client. This field is required only if CacheProvider is set to
	// CustomCacheType.
	CustomConfiguration *CustomConfig
	// RedisConfiguration is a configuration for a redis cache client. This field is required only if CacheProvider is set to
	// RedisCacheType.
	RedisConfiguration *RedisConfig
}

Config is a configuration struct for the cache client. It allows the user to specify the type of cache they want to use as well as the configuration for that cache type.

func (*Config) Freeze

func (c *Config) Freeze() (*Client, error)

Freeze freezes the cache configuration and generates the respective cache clients.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the cache configuration.

type CustomConfig

type CustomConfig struct {
	Client ClientAPIs
}

CustomConfig is a configuration struct for a custom cache client.

type IGet

type IGet interface {
	Get(ctx context.Context, key string) ([]byte, error)
}

IGet is an interface for all cache clients that support Get operations.

type ISet

type ISet interface {
	Set(ctx context.Context, key string, val any, ttl time.Duration) error
}

ISet is an interface for all cache clients that support Set operations.

type RedisConfig

type RedisConfig struct {
	// RedisServerType is a constant that defines which redis server type the user is using.
	RedisServerType constants.RedisType
	// SingularConfig is the configuration for a singular redis server. This is required only if RedisServerType
	// is set to SingularRedisType.
	SingularConfig *redis.Options
	// ClusterConfig is the configuration for a redis cluster. This is required only if RedisServerType
	// is set to ClusterRedisType.
	ClusterConfig *redis.ClusterOptions
}

RedisConfig is the configuration for the redis client.

Jump to

Keyboard shortcuts

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