cache

package
v1.0.1-0...-32d7d0a Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Unlicense Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMemConfig = MemConfig{
		CleanupInterval:          0,
		LimiterRequestsPerSecond: 30000,
		LimiterBurst:             300,
		TimeToLive:               0,
	}
	DefaultRedisConfig = RedisConfig{
		Host:                     "localhost",
		Port:                     "6379",
		RetryTimes:               4,
		RetryPause:               5 * time.Second,
		Timeout:                  30 * time.Second,
		LimiterRequestsPerSecond: 1,
		LimiterBurst:             1,
		TimeToLive:               3 * time.Second,
		TxRetries:                1,
	}
)

Functions

func New

func New(ctx context.Context, conf CacheConfig) (domain.Cacher, error)

func WithHeartbeatCleanup

func WithHeartbeatCleanup(ch chan<- any) options

func WithHeartbeatPair

func WithHeartbeatPair(ch chan<- any) options

func WithHeartbeatToken

func WithHeartbeatToken(ch chan<- any) options

Types

type CacheConfig

type CacheConfig struct {
	Cache string      `mapstructure:"APP_CACHE" validate:"required"`
	Mem   MemConfig   `mapstructure:",squash"`
	Redis RedisConfig `mapstructure:",squash"`
}

type Mem

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

func NewMem

func NewMem(conf MemConfig, opts ...options) *Mem

func (*Mem) Add

func (m *Mem) Add(_ context.Context, queue uint64, album uint64) error

func (*Mem) Allow

func (m *Mem) Allow(_ context.Context, ip uint64) (bool, error)

func (*Mem) Del

func (m *Mem) Del(_ context.Context, token uint64) error

func (*Mem) Get

func (m *Mem) Get(_ context.Context, token uint64) (uint64, uint64, error)

func (*Mem) Health

func (m *Mem) Health(_ context.Context) (bool, error)

func (*Mem) Monitor

func (m *Mem) Monitor(ctx context.Context)

func (*Mem) PAdd

func (m *Mem) PAdd(_ context.Context, pqueue uint64, album uint64, expires time.Time) error

func (*Mem) PPoll

func (m *Mem) PPoll(_ context.Context, pqueue uint64) (uint64, time.Time, error)

func (*Mem) PSize

func (m *Mem) PSize(_ context.Context, pqueue uint64) (int, error)

func (*Mem) Poll

func (m *Mem) Poll(_ context.Context, queue uint64) (uint64, error)

func (*Mem) Pop

func (m *Mem) Pop(_ context.Context, album uint64) (uint64, uint64, error)

func (*Mem) Push

func (m *Mem) Push(_ context.Context, album uint64, pairs [][2]uint64) error

func (*Mem) Reset

func (m *Mem) Reset() error

func (*Mem) Set

func (m *Mem) Set(_ context.Context, token uint64, album uint64, image uint64) error

func (*Mem) Size

func (m *Mem) Size(_ context.Context, queue uint64) (int, error)

type MemConfig

type MemConfig struct {
	CleanupInterval          time.Duration `mapstructure:"CACHE_MEM_CLEANUP_INTERVAL"             validate:"required"`
	LimiterRequestsPerSecond float64       `mapstructure:"MIDDLEWARE_LIMITER_REQUESTS_PER_SECOND" validate:"required"`
	LimiterBurst             int           `mapstructure:"MIDDLEWARE_LIMITER_BURST"               validate:"required"`
	TimeToLive               time.Duration `mapstructure:"CACHE_REDIS_TIME_TO_LIVE"               validate:"required"`
}

type Redis

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

func NewRedis

func NewRedis(ctx context.Context, conf RedisConfig) (*Redis, error)

func (*Redis) Add

func (r *Redis) Add(ctx context.Context, queue uint64, album uint64) error

func (*Redis) Allow

func (r *Redis) Allow(ctx context.Context, ip uint64) (bool, error)

func (*Redis) Close

func (r *Redis) Close(_ context.Context) error

func (*Redis) Del

func (r *Redis) Del(ctx context.Context, token uint64) error

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, token uint64) (uint64, uint64, error)

func (*Redis) Health

func (r *Redis) Health(ctx context.Context) (bool, error)

func (*Redis) PAdd

func (r *Redis) PAdd(ctx context.Context, pqueue uint64, album uint64, expires time.Time) error

func (*Redis) PPoll

func (r *Redis) PPoll(ctx context.Context, pqueue uint64) (uint64, time.Time, error)

func (*Redis) PSize

func (r *Redis) PSize(ctx context.Context, pqueue uint64) (int, error)

func (*Redis) Poll

func (r *Redis) Poll(ctx context.Context, queue uint64) (uint64, error)

func (*Redis) Pop

func (r *Redis) Pop(ctx context.Context, album uint64) (uint64, uint64, error)

func (*Redis) Push

func (r *Redis) Push(ctx context.Context, album uint64, pairs [][2]uint64) error

func (*Redis) Reset

func (r *Redis) Reset() error

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, token uint64, album uint64, image uint64) error

func (*Redis) Size

func (r *Redis) Size(ctx context.Context, queue uint64) (int, error)

type RedisConfig

type RedisConfig struct {
	Host                     string        `mapstructure:"CACHE_REDIS_HOST"                       validate:"required"`
	Port                     string        `mapstructure:"CACHE_REDIS_PORT"                       validate:"required"`
	RetryTimes               int           `mapstructure:"CACHE_REDIS_RETRY_TIMES"                validate:"required"`
	RetryPause               time.Duration `mapstructure:"CACHE_REDIS_RETRY_PAUSE"                validate:"required"`
	Timeout                  time.Duration `mapstructure:"CACHE_REDIS_TIMEOUT"                    validate:"required"`
	LimiterRequestsPerSecond int           `mapstructure:"MIDDLEWARE_LIMITER_REQUESTS_PER_SECOND" validate:"required"`
	LimiterBurst             int64         `mapstructure:"MIDDLEWARE_LIMITER_BURST"               validate:"required"`
	TimeToLive               time.Duration `mapstructure:"CACHE_REDIS_TIME_TO_LIVE"               validate:"required"`
	TxRetries                int           `mapstructure:"CACHE_REDIS_TX_RETRIES"                 validate:"required"`
}

Jump to

Keyboard shortcuts

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