Documentation
¶
Index ¶
- type BigCache
- func (bc *BigCache[T]) Delete(_ context.Context, key string) error
- func (bc *BigCache[T]) Get(_ context.Context, key string, expire time.Duration) (T, bool)
- func (bc *BigCache[T]) MDelete(ctx context.Context, keys []string) error
- func (bc *BigCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T
- func (bc *BigCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error
- func (bc *BigCache[T]) Ping(_ context.Context) (string, error)
- func (bc *BigCache[T]) Set(_ context.Context, key string, data T, createTime time.Time) error
- func (bc *BigCache[T]) SetDefault(_ context.Context, keys []string, createTime time.Time) error
- type Cache
- type FreeCache
- func (fc *FreeCache[T]) Delete(_ context.Context, key string) error
- func (fc *FreeCache[T]) Get(_ context.Context, key string, expire time.Duration) (T, bool)
- func (fc *FreeCache[T]) MDelete(_ context.Context, keys []string) error
- func (fc *FreeCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T
- func (fc *FreeCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error
- func (fc *FreeCache[T]) Ping(_ context.Context) (string, error)
- func (fc *FreeCache[T]) Set(_ context.Context, key string, data T, createTime time.Time) error
- func (fc *FreeCache[T]) SetDefault(_ context.Context, keys []string, createTime time.Time) error
- type LRUCache
- func (lc *LRUCache[T]) Delete(_ context.Context, key string) error
- func (lc *LRUCache[T]) Get(_ context.Context, key string, expire time.Duration) (T, bool)
- func (lc *LRUCache[T]) MDelete(ctx context.Context, keys []string) error
- func (lc *LRUCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T
- func (lc *LRUCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error
- func (lc *LRUCache[T]) Ping(_ context.Context) (string, error)
- func (lc *LRUCache[T]) Set(_ context.Context, key string, data T, createTime time.Time) error
- func (lc *LRUCache[T]) SetDefault(ctx context.Context, keys []string, createTime time.Time) error
- type Mocker
- func (m *Mocker[T]) Delete(ctx context.Context, key string) error
- func (m *Mocker[T]) Get(ctx context.Context, key string, expire time.Duration) (T, bool)
- func (m *Mocker[T]) MDelete(ctx context.Context, keys []string) error
- func (m *Mocker[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T
- func (m *Mocker[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error
- func (m *Mocker[T]) MockDelete(mockFn func(ctx context.Context, key string) error) *Mocker[T]
- func (m *Mocker[T]) MockGet(mockFn func(ctx context.Context, key string, expire time.Duration) (T, bool)) *Mocker[T]
- func (m *Mocker[T]) MockMDelete(mockFn func(ctx context.Context, keys []string) error) *Mocker[T]
- func (m *Mocker[T]) MockMGet(...) *Mocker[T]
- func (m *Mocker[T]) MockMSet(mockFn func(ctx context.Context, kvs map[string]T, createTime time.Time) error) *Mocker[T]
- func (m *Mocker[T]) MockPing(mockFn func(ctx context.Context) (string, error)) *Mocker[T]
- func (m *Mocker[T]) MockSet(...) *Mocker[T]
- func (m *Mocker[T]) MockSetDefault(mockFn func(ctx context.Context, keys []string, createTime time.Time) error) *Mocker[T]
- func (m *Mocker[T]) Ping(ctx context.Context) (string, error)
- func (m *Mocker[T]) Set(ctx context.Context, key string, data T, createTime time.Time) error
- func (m *Mocker[T]) SetDefault(ctx context.Context, keys []string, createTime time.Time) error
- type RedisCache
- func (rc *RedisCache[T]) Delete(ctx context.Context, key string) error
- func (rc *RedisCache[T]) Get(ctx context.Context, key string, expire time.Duration) (T, bool)
- func (rc *RedisCache[T]) MDelete(ctx context.Context, keys []string) error
- func (rc *RedisCache[T]) MGet(ctx context.Context, keys []string, expire time.Duration) map[string]T
- func (rc *RedisCache[T]) MSet(ctx context.Context, kvs map[string]T, createTime time.Time) error
- func (rc *RedisCache[T]) Ping(ctx context.Context) (string, error)
- func (rc *RedisCache[T]) Set(ctx context.Context, key string, data T, createTime time.Time) error
- func (rc *RedisCache[T]) SetDefault(ctx context.Context, keys []string, createTime time.Time) error
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 ¶
NewBigCache returns a newly initialize BigCache implement Cache with ttl, the bigcache config use bigcache.DefaultConfig
func NewBigCacheWithConfig ¶
NewBigCacheWithConfig returns a newly initialize BigCache implement Cache with bigcache config,
cfg: bigcache.Config
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 ¶
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
type LRUCache ¶ added in v1.0.3
type LRUCache[T any] struct { // contains filtered or unexported fields }
func NewLRUCache ¶ added in v1.0.3
NewLRUCache returns a newly initialize LRUCache implement Cache with ttl and size
type Mocker ¶
type Mocker[T any] struct { // contains filtered or unexported fields }
func NewCacheMocker ¶
func (*Mocker[T]) MockDelete ¶
func (*Mocker[T]) MockMDelete ¶
func (*Mocker[T]) MockSetDefault ¶ added in v1.0.3
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]) MDelete ¶
func (rc *RedisCache[T]) MDelete(ctx context.Context, keys []string) error