zizou

package module
v0.3.2-0...-b9e4799 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: MIT Imports: 6 Imported by: 1

README

zizou

In memory cache implementation with high concurrency

Features

  • Store millions of entries
  • High concurrent thread-safe access
  • Expiration support
  • Shard support to avoid locks on whole db during any concurrent read/writes/deletes

Example Usage

config:=zizou.Config{
	SweepTime:10*time.Minute,
	ShardSize: 256,
}
cache,err:=zizou.New(&config)
cache.Set("foo", "bar", 10*time.Second)
item, found := cache.Get("foo")

Performance

		BenchmarkCacheGetExpiring-4                	20000000	        70.0 ns/op
		BenchmarkCacheGetNotExpiring-4             	20000000	       119 ns/op
		BenchmarkCacheGetConcurrentExpiring-4      	20000000	        59.3 ns/op
		BenchmarkCacheGetConcurrentNotExpiring-4   	20000000	        91.3 ns/op
		BenchmarkCacheSetExpiring-4                	10000000	       172 ns/op
		BenchmarkCacheSetNotExpiring-4             	10000000	       134 ns/op
		BenchmarkCacheSetDelete-4                  	 5000000	       343 ns/op

TODO

  • Store data as a map of string and byte array to avoid lookups on object, which will be copied in memory
  • Make a circular shard ring, cache objects in individual shard for better concurrency and to avoid locks on the whole cache map object (LRU implementation)
  • Use eviction policies of key using a list object, evict those at front
  • Implement operations using cmdable interface as done in go-redis(design pattern)
  • Check how GC can be avoided

Zizou Image source: https://www.pinterest.ca/pin/436075176391410672/?lp=true

Documentation

Index

Constants

View Source
const (
	DefaultEvictionTime = 600 * time.Second
	MinimumStartupTime  = 300 * time.Millisecond
	MaximumStartupTime  = 2 * MinimumStartupTime
)

Variables

View Source
var (
	ERR_INVALID_CONFIG = errors.New("invalid configuration")
)

Functions

This section is empty.

Types

type Cache

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

func New

func New(cnf *Config) (*Cache, error)

func (*Cache) Delete

func (c *Cache) Delete(k string) bool

func (*Cache) Flush

func (c *Cache) Flush()

func (*Cache) Get

func (c *Cache) Get(k string) (interface{}, bool)

func (*Cache) Set

func (c *Cache) Set(k string, v interface{}, dur time.Duration) error

type Config

type Config struct {
	SweepTime time.Duration
	ShardSize uint64
}

func (*Config) Validate

func (c *Config) Validate() bool

Jump to

Keyboard shortcuts

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