cache

package
v0.2.27 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorValueExpired = errors.New("cached value expired")
View Source
var ErrorValueExpiredOrNotExist = errors.New("cached value expired or not exist")

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (interface{}, error)
	Set(ctx context.Context, key string, value interface{}) error
	SetEx(ctx context.Context, key string, value interface{}, expire time.Duration) error
	Delete(ctx context.Context, key string) (bool, error)
	Exist(ctx context.Context, key string) (bool, error)
}

func NewMemLruCache

func NewMemLruCache(_ context.Context, size int) (Cache, error)

func NewSingleFlightCache

func NewSingleFlightCache(ctx context.Context, cacheTime time.Duration, fn SingleFlightFunc) (Cache, error)

type MemLruCache

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

func (*MemLruCache) Delete

func (m *MemLruCache) Delete(_ context.Context, key string) (bool, error)

func (*MemLruCache) Exist

func (m *MemLruCache) Exist(_ context.Context, key string) (bool, error)

func (*MemLruCache) Get

func (m *MemLruCache) Get(_ context.Context, key string) (interface{}, error)

func (*MemLruCache) Set

func (m *MemLruCache) Set(ctx context.Context, key string, value interface{}) error

func (*MemLruCache) SetEx

func (m *MemLruCache) SetEx(ctx context.Context, key string, value interface{}, expire time.Duration) error

type RedisCache

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

func NewRedisCache

func NewRedisCache(client *redis.Client) *RedisCache

func (RedisCache) Delete

func (s RedisCache) Delete(ctx context.Context, key string) (bool, error)

func (RedisCache) Exist

func (s RedisCache) Exist(ctx context.Context, key string) (bool, error)

func (RedisCache) Get

func (s RedisCache) Get(ctx context.Context, key string) (interface{}, error)

func (RedisCache) Set

func (s RedisCache) Set(ctx context.Context, key string, value interface{}) error

func (RedisCache) SetEx

func (s RedisCache) SetEx(ctx context.Context, key string, value interface{}, expire time.Duration) error

type SingleFlightCache

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

func (*SingleFlightCache) Delete

func (s *SingleFlightCache) Delete(_ context.Context, _ string) (bool, error)

func (*SingleFlightCache) Exist

func (s *SingleFlightCache) Exist(_ context.Context, _ string) (bool, error)

func (*SingleFlightCache) Get

func (s *SingleFlightCache) Get(ctx context.Context, _ string) (interface{}, error)

func (*SingleFlightCache) Set

func (s *SingleFlightCache) Set(_ context.Context, _ string, value interface{}) error

func (*SingleFlightCache) SetEx

func (s *SingleFlightCache) SetEx(_ context.Context, _ string, value interface{}, expire time.Duration) error

type SingleFlightFunc

type SingleFlightFunc func(ctx context.Context) (data interface{}, err error)

Jump to

Keyboard shortcuts

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