cache

package
v0.0.0-...-2defda7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisClientWithConfig

func NewRedisClientWithConfig(config *redis.Options, logger *zap.Logger) (*redis.Client, error)

Types

type Cache

type Cache interface {
	// Set armazena um valor no cache com tempo de expiração
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

	// Get recupera um valor do cache
	Get(ctx context.Context, key string, dest interface{}) (bool, error)

	// Delete remove um valor do cache
	Delete(ctx context.Context, key string) error

	// Clear remove todos os valores do cache
	Clear(ctx context.Context) error

	// Ping verifica se o cache está acessível
	Ping(ctx context.Context) error
}

Cache define a interface para operações de cache

type MemoryCache

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

MemoryCache implementa a interface Cache usando armazenamento em memória

func NewMemoryCache

func NewMemoryCache(defaultExpiration, cleanupInterval time.Duration, metrics *metrics.APIMetrics, logger *zap.Logger) *MemoryCache

NewMemoryCache cria uma nova instância de MemoryCache

func (*MemoryCache) Clear

func (c *MemoryCache) Clear(ctx context.Context) error

Clear remove todos os valores do cache

func (*MemoryCache) Delete

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

Delete remove um valor do cache

func (*MemoryCache) Get

func (c *MemoryCache) Get(ctx context.Context, key string, dest interface{}) (bool, error)

Get recupera um valor do cache

func (*MemoryCache) Ping

func (c *MemoryCache) Ping(ctx context.Context) error

Ping verifica se o cache está funcionando

func (*MemoryCache) Set

func (c *MemoryCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set armazena um valor no cache

type NoOpCache

type NoOpCache struct{}

NoOpCache é uma implementação de Cache que não faz nada Usada quando o cache está desabilitado na configuração

func (*NoOpCache) Clear

func (c *NoOpCache) Clear(ctx context.Context) error

Clear no-op: não faz nada

func (*NoOpCache) Delete

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

Delete no-op: não faz nada

func (*NoOpCache) Get

func (c *NoOpCache) Get(ctx context.Context, key string, dest interface{}) (bool, error)

Get no-op: sempre retorna cache miss

func (*NoOpCache) Ping

func (c *NoOpCache) Ping(ctx context.Context) error

Ping no-op: sempre retorna sucesso

func (*NoOpCache) Set

func (c *NoOpCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set no-op: não faz nada

type RedisCache

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

RedisCache implementa a interface Cache usando Redis

func NewRedisCache

func NewRedisCache(addr string, password string, db int, logger *zap.Logger) (*RedisCache, error)

NewRedisCache cria uma nova instância de RedisCache

func (*RedisCache) Clear

func (c *RedisCache) Clear(ctx context.Context) error

Clear remove todos os valores do cache

func (*RedisCache) ClearPattern

func (c *RedisCache) ClearPattern(ctx context.Context, pattern string) error

ClearPattern remove valores do cache por padrão

func (*RedisCache) Delete

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

Delete remove um valor do cache

func (*RedisCache) Get

func (c *RedisCache) Get(ctx context.Context, key string, dest interface{}) (bool, error)

Get recupera um valor do cache

func (*RedisCache) Ping

func (c *RedisCache) Ping(ctx context.Context) error

Ping verifica se o Redis está acessível

func (*RedisCache) Set

func (c *RedisCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set armazena um valor no cache

Jump to

Keyboard shortcuts

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