gocake

package module
v0.0.0-...-0fe4d6e Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 7 Imported by: 0

README

gocake

Golang in-memory cache library

How it work

  • Sharding the hashed key for each stores.
  • Using LFU for eviction policy.
  • Thread safe.
  • Handle expired async.
  • Handle set a pointer as value.

Future

  • Don't use the builtin map from Golang to avoid out of memory issue.
  • Avoid to use pointer as much as possible to reduce GC overhead.
  • Using CRFP (mix LRU/LFU) for eviction policy to optimize hit rate.
  • Using WTinyLFU for admission policy to optimize hit rate.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheMiss = errors.New("cache miss")
)

All errors of the library.

Functions

func NewCache

func NewCache(size int, hasher Hasher) *cache

NewCache creates a new cache with the given capacity.

Types

type Cache

type Cache interface {
	Get(key string) (interface{}, error)
	GetMany(mapItems map[string]interface{}) error
	Set(key string, value interface{}) error
	SetWithTTL(key string, value interface{}, ttl time.Duration) error
	SetMany(mapItems map[string]interface{}) error
	SetManyWithTTL(mapItems map[string]interface{}, ttl time.Duration) error
	Delete(key string) error
	DeleteMany(key []string) error
	Clear() error
}

Cache is a fast in-memory cache with the optimised storage for avoiding GC overhead. It is thread-safe and optimze for maximum hit ratio.

type Hasher

type Hasher interface {
	Sum64(data string) uint64
}

func DefaultHasher

func DefaultHasher() Hasher

Jump to

Keyboard shortcuts

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