cache

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigCache

type BigCache[T any] struct {
	// contains filtered or unexported fields
}

func NewBigCache

func NewBigCache[T any](ttl time.Duration) *BigCache[T]

NewBigCache returns a newly initialize BigCache implement Cache with ttl, the bigcache config use bigcache.DefaultConfig

func NewBigCacheWithConfig

func NewBigCacheWithConfig[T any](cfg bigcache.Config) (*BigCache[T], error)

NewBigCacheWithConfig returns a newly initialize BigCache implement Cache with bigcache config,

cfg: bigcache.Config

func (*BigCache[T]) Delete

func (bc *BigCache[T]) Delete(_ context.Context, key string) error

func (*BigCache[T]) Get

func (bc *BigCache[T]) Get(_ context.Context, key string, expire time.Duration) (T, bool)

func (*BigCache[T]) MDelete

func (bc *BigCache[T]) MDelete(ctx context.Context, keys []string) error

func (*BigCache[T]) MGet

func (bc *BigCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T

func (*BigCache[T]) MSet

func (bc *BigCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error

func (*BigCache[T]) Ping

func (bc *BigCache[T]) Ping(_ context.Context) (string, error)

func (*BigCache[T]) Set

func (bc *BigCache[T]) Set(_ context.Context, key string, data T, createTime time.Time) error

func (*BigCache[T]) SetDefault added in v1.0.3

func (bc *BigCache[T]) SetDefault(_ context.Context, keys []string, createTime time.Time) error

type Cache

type Cache[T any] interface {
	Get(ctx context.Context, key string, expire time.Duration) (data T, ok bool)
	MGet(ctx context.Context, keys []string, expire time.Duration) (data map[string]T)
	Set(ctx context.Context, key string, data T, createTime time.Time) error
	MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error
	SetDefault(ctx context.Context, keys []string, createTime time.Time) error
	Delete(ctx context.Context, key string) error
	MDelete(ctx context.Context, keys []string) error
	Ping(ctx context.Context) (string, error)
}

type FreeCache

type FreeCache[T any] struct {
	// contains filtered or unexported fields
}

func NewFreeCache

func NewFreeCache[T any](size int, ttl time.Duration) *FreeCache[T]

NewFreeCache returns a newly initialize FreeCache implement Cache by size and ttl

size: size in bytes, e.g. 100*1024*1024 is 100 MB

ttl: cache expire ttl, if ttl set 0, cache will not expire

func (*FreeCache[T]) Delete

func (fc *FreeCache[T]) Delete(_ context.Context, key string) error

func (*FreeCache[T]) Get

func (fc *FreeCache[T]) Get(_ context.Context, key string, expire time.Duration) (T, bool)

func (*FreeCache[T]) MDelete

func (fc *FreeCache[T]) MDelete(_ context.Context, keys []string) error

func (*FreeCache[T]) MGet

func (fc *FreeCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T

func (*FreeCache[T]) MSet

func (fc *FreeCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error

func (*FreeCache[T]) Ping

func (fc *FreeCache[T]) Ping(_ context.Context) (string, error)

func (*FreeCache[T]) Set

func (fc *FreeCache[T]) Set(_ context.Context, key string, data T, createTime time.Time) error

func (*FreeCache[T]) SetDefault added in v1.0.3

func (fc *FreeCache[T]) SetDefault(_ context.Context, keys []string, createTime time.Time) error

type LRUCache added in v1.0.3

type LRUCache[T any] struct {
	// contains filtered or unexported fields
}

func NewLRUCache added in v1.0.3

func NewLRUCache[T any](size int, ttl time.Duration) *LRUCache[T]

NewLRUCache returns a newly initialize LRUCache implement Cache with ttl and size

func (*LRUCache[T]) Delete added in v1.0.3

func (lc *LRUCache[T]) Delete(_ context.Context, key string) error

func (*LRUCache[T]) Get added in v1.0.3

func (lc *LRUCache[T]) Get(_ context.Context, key string, expire time.Duration) (T, bool)

func (*LRUCache[T]) MDelete added in v1.0.3

func (lc *LRUCache[T]) MDelete(ctx context.Context, keys []string) error

func (*LRUCache[T]) MGet added in v1.0.3

func (lc *LRUCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T

func (*LRUCache[T]) MSet added in v1.0.3

func (lc *LRUCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error

func (*LRUCache[T]) Ping added in v1.0.3

func (lc *LRUCache[T]) Ping(_ context.Context) (string, error)

func (*LRUCache[T]) Set added in v1.0.3

func (lc *LRUCache[T]) Set(_ context.Context, key string, data T, createTime time.Time) error

func (*LRUCache[T]) SetDefault added in v1.0.3

func (lc *LRUCache[T]) SetDefault(ctx context.Context, keys []string, createTime time.Time) error

type Mocker

type Mocker[T any] struct {
	// contains filtered or unexported fields
}

func NewCacheMocker

func NewCacheMocker[T any]() *Mocker[T]

func (*Mocker[T]) Delete

func (m *Mocker[T]) Delete(ctx context.Context, key string) error

func (*Mocker[T]) Get

func (m *Mocker[T]) Get(ctx context.Context, key string, expire time.Duration) (T, bool)

func (*Mocker[T]) MDelete

func (m *Mocker[T]) MDelete(ctx context.Context, keys []string) error

func (*Mocker[T]) MGet

func (m *Mocker[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T

func (*Mocker[T]) MSet

func (m *Mocker[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error

func (*Mocker[T]) MockDelete

func (m *Mocker[T]) MockDelete(mockFn func(ctx context.Context, key string) error) *Mocker[T]

func (*Mocker[T]) MockGet

func (m *Mocker[T]) MockGet(mockFn func(ctx context.Context, key string, expire time.Duration) (T, bool)) *Mocker[T]

func (*Mocker[T]) MockMDelete

func (m *Mocker[T]) MockMDelete(mockFn func(ctx context.Context, keys []string) error) *Mocker[T]

func (*Mocker[T]) MockMGet

func (m *Mocker[T]) MockMGet(mockFn func(ctx context.Context, keys []string, expire time.Duration) map[string]T) *Mocker[T]

func (*Mocker[T]) MockMSet

func (m *Mocker[T]) MockMSet(mockFn func(ctx context.Context, kvs map[string]T, createTime time.Time) error) *Mocker[T]

func (*Mocker[T]) MockPing

func (m *Mocker[T]) MockPing(mockFn func(ctx context.Context) (string, error)) *Mocker[T]

func (*Mocker[T]) MockSet

func (m *Mocker[T]) MockSet(mockFn func(ctx context.Context, key string, data T, createTime time.Time) error) *Mocker[T]

func (*Mocker[T]) MockSetDefault added in v1.0.3

func (m *Mocker[T]) MockSetDefault(mockFn func(ctx context.Context, keys []string, createTime time.Time) error) *Mocker[T]

func (*Mocker[T]) Ping

func (m *Mocker[T]) Ping(ctx context.Context) (string, error)

func (*Mocker[T]) Set

func (m *Mocker[T]) Set(ctx context.Context, key string, data T, createTime time.Time) error

func (*Mocker[T]) SetDefault added in v1.0.3

func (m *Mocker[T]) SetDefault(ctx context.Context, keys []string, createTime time.Time) error

type RedisCache

type RedisCache[T any] struct {
	// contains filtered or unexported fields
}

func NewRedisCacheWithClient

func NewRedisCacheWithClient[T any](client *redis.Client, ttl time.Duration) *RedisCache[T]

NewRedisCacheWithClient returns a newly initialize RedisCache implement Cache by client and ttl

client: redis client, need github.com/redis/go-redis/v9 *redis.Client ttl: redis expire ttl, if ttl set 0, cache will not expire

func NewRedisCacheWithOptions

func NewRedisCacheWithOptions[T any](options *redis.Options, ttl time.Duration) *RedisCache[T]

NewRedisCacheWithOptions returns a newly initialize RedisCache implement Cache by redis options and ttl

options: redis options, need github.com/redis/go-redis/v9 *redis.Options ttl: redis expire ttl, if ttl set 0, cache will not expire

func (*RedisCache[T]) Delete

func (rc *RedisCache[T]) Delete(ctx context.Context, key string) error

func (*RedisCache[T]) Get

func (rc *RedisCache[T]) Get(ctx context.Context, key string, expire time.Duration) (T, bool)

func (*RedisCache[T]) MDelete

func (rc *RedisCache[T]) MDelete(ctx context.Context, keys []string) error

func (*RedisCache[T]) MGet

func (rc *RedisCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T

func (*RedisCache[T]) MSet

func (rc *RedisCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error

func (*RedisCache[T]) Ping

func (rc *RedisCache[T]) Ping(ctx context.Context) (string, error)

func (*RedisCache[T]) Set

func (rc *RedisCache[T]) Set(ctx context.Context, key string, data T, createTime time.Time) error

func (*RedisCache[T]) SetDefault added in v1.0.3

func (rc *RedisCache[T]) SetDefault(ctx context.Context, keys []string, createTime time.Time) error

Jump to

Keyboard shortcuts

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