cache

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 12 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 {
	// Ping
	// ICMP ping for checking connection
	// but be careful in some cases infrastructure filter ICMP packets for prevention of this protocol attacks
	Ping(ctx context.Context) error
	// GetKey
	// to read specific key from cache
	// method :: used for metrics
	// key :: the item which you wish to find in cache
	GetKey(ctx context.Context, method string, key string) (string, error)
	// Set
	// to store specified item with specified key and value in cache
	// method :: used for metrics
	// key, val :: specified key and corresponding value in cache
	Set(ctx context.Context, method string, key string, val string, expiration time.Duration) error

	//RemoveKey
	// to remove specific key from cache
	// method :: used for metrics
	// key :: the item which you wish to remove from the cache
	RemoveKey(ctx context.Context, method string, key string) error
}

Cache this interface give us an abstraction over internal cache we are using currently the cache repo contains in-memory cache and redis cache which is a de-facto

func NewInMemoryCache

func NewInMemoryCache(evictionInterval time.Duration, options ...Option) (Cache, error)

func NewRedisCache

func NewRedisCache(options ...Option) (Cache, error)

NewRedisCache in order to use single redis, just give single address in redis addresses and for enabling redis sentinel mode, give cluster master-name and list of cluster members addresses

type Error

type Error error
var (
	NotFoundError Error = errors.New("key not-found")
)

type Option

type Option func(cache Cache) error

func WithAddresses

func WithAddresses(masterName *string, redisAddress ...string) Option

WithAddresses in order to use single instance give master name empty string, and redis addresses ad single item

func WithConnectionStringOption

func WithConnectionStringOption(connectionString string) Option

WithConnectionStringOption this model will configure redis in the way which we have a connection string and we have to pars this string and create redis options

func WithDbNumber

func WithDbNumber(dbNumber int) Option

func WithLoggerOption

func WithLoggerOption(logger logger.Logger) Option

WithLoggerOption this option enables error logging on cache instance for you

func WithMaxRetry

func WithMaxRetry(maxRetry int) Option

func WithMetricOption

func WithMetricOption(metric metric.Metric) Option

WithMetricOption this option allows you to define metric for your cache instance

func WithTimeout

func WithTimeout(timeout time.Duration) Option

Jump to

Keyboard shortcuts

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