Documentation
¶
Index ¶
- Variables
- func Fnv32(key []byte) uint32
- func KeyToHash(key interface{}) uint64
- func MemHash(data []byte) uint64
- func MemHashString(str string) uint64
- func RandString(l int) string
- func XXHashString(str string) uint64
- type ArcCache
- func (c *ArcCache) Evict(ctx context.Context, count int)
- func (c *ArcCache) Exists(ctx context.Context, key string) bool
- func (c *ArcCache) Get(ctx context.Context, key string) (interface{}, error)
- func (c *ArcCache) Init(clock Clock, capacity int)
- func (c *ArcCache) Remove(ctx context.Context, key string) bool
- func (c *ArcCache) Set(ctx context.Context, key string, val interface{}, ttl time.Duration) error
- type Cache
- type CachePolicy
- type Clock
- type FakeClock
- type LfuCache
- func (c *LfuCache) Evict(ctx context.Context, count int)
- func (c *LfuCache) Exists(ctx context.Context, key string) bool
- func (c *LfuCache) Get(ctx context.Context, key string) (interface{}, error)
- func (c *LfuCache) Init(clock Clock, capacity int)
- func (c *LfuCache) Remove(ctx context.Context, key string) bool
- func (c *LfuCache) Set(ctx context.Context, key string, val interface{}, ttl time.Duration) error
- type LoaderFunc
- type LruCache
- func (c *LruCache) Evict(ctx context.Context, count int)
- func (c *LruCache) Exists(ctx context.Context, key string) bool
- func (c *LruCache) Get(ctx context.Context, key string) (interface{}, error)
- func (c *LruCache) Init(clock Clock, capacity int)
- func (c *LruCache) Remove(ctx context.Context, key string) bool
- func (c *LruCache) Set(ctx context.Context, key string, val interface{}, ttl time.Duration) error
- type MLoaderFunc
- type Option
- func WithDefaultVal(defaultVal interface{}) Option
- func WithLoaderFn(fn LoaderFunc) Option
- func WithMLoaderFn(fn MLoaderFunc) Option
- func WithRedisClient(client *redis.Client) Option
- func WithRedisOptions(opts *redis.Options) Option
- func WithTTL(ttl time.Duration) Option
- func WithUnSafeValBind(valPtrFunc valuePtrFunc) Option
- type RedisCli
- type SimpleCache
- func (c *SimpleCache) Evict(ctx context.Context, count int)
- func (c *SimpleCache) Exists(ctx context.Context, key string) bool
- func (c *SimpleCache) Get(ctx context.Context, key string) (interface{}, error)
- func (c *SimpleCache) Init(clock Clock, capacity int)
- func (c *SimpleCache) Remove(ctx context.Context, key string) bool
- func (c *SimpleCache) Set(ctx context.Context, key string, val interface{}, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( KeyNotFoundError = errors.New("mcache: key not found.") KeyExpiredError = errors.New("mcache: key expired.") RedisNotFoundError = errors.New("mcache: redis not found.") SerializeError = errors.New("mcache: must set WithSafeValPtrFunc option!") KeyValueLenError = errors.New("mcache: len of key != len of value.") DefaultValueSetError = errors.New("mcache: set def val, 1min expiration.") )
Functions ¶
func MemHash ¶
MemHash is the hash function used by go map, it utilizes available hardware instructions(behaves as aeshash if aes instruction is available). NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash.
func MemHashString ¶
MemHashString is the hash function used by go map, it utilizes available hardware instructions (behaves as aeshash if aes instruction is available). NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash.
func RandString ¶
func XXHashString ¶
Types ¶
type Cache ¶
type Cache interface { Set(ctx context.Context, key string, value interface{}, opts ...Option) error MSet(ctx context.Context, keys []string, values []interface{}, opts ...Option) error Get(ctx context.Context, key string, opts ...Option) (interface{}, error) MGet(ctx context.Context, keys []string, opts ...Option) (map[string]interface{}, error) Remove(ctx context.Context, key string) bool MRemove(ctx context.Context, keys []string) bool Exists(ctx context.Context, key string) bool //only for debug DebugShardIndex(key string) uint64 // contains filtered or unexported methods }
type CachePolicy ¶
type CachePolicy[T any] interface { Init(clock Clock, capacity int) Set(ctx context.Context, key string, val interface{}, ttl time.Duration) error Get(ctx context.Context, key string) (interface{}, error) Exists(ctx context.Context, key string) bool Remove(ctx context.Context, key string) bool Evict(ctx context.Context, count int) *T }
type FakeClock ¶
func NewFakeClock ¶
func NewFakeClock() FakeClock
type Option ¶
type Option func(*options)
func WithDefaultVal ¶
func WithDefaultVal(defaultVal interface{}) Option
func WithLoaderFn ¶
func WithLoaderFn(fn LoaderFunc) Option
func WithMLoaderFn ¶
func WithMLoaderFn(fn MLoaderFunc) Option
func WithRedisClient ¶
func WithRedisClient(client *redis.Client) Option
func WithRedisOptions ¶
func WithRedisOptions(opts *redis.Options) Option
func WithUnSafeValBind ¶
func WithUnSafeValBind(valPtrFunc valuePtrFunc) Option
type SimpleCache ¶
func (*SimpleCache) Get ¶
func (c *SimpleCache) Get(ctx context.Context, key string) (interface{}, error)
func (*SimpleCache) Init ¶
func (c *SimpleCache) Init(clock Clock, capacity int)
Click to show internal directories.
Click to hide internal directories.