Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 879 Bytes

README.md

File metadata and controls

47 lines (35 loc) · 879 Bytes

scache

Cache library for golang. It supports expirable cache: LRU

Install

go get github.com/khevse/scache

Examples

Simple:

c, err := scache.New(100, 10000).TTL(time.Hour).LRU().Build()

With loader function:

loadFunc = func(key interface{}) (value interface{}, err error) {
    ... load from DB
    value = rowData
    return
}

c, err := scache.New(10, 10000).LRU().LoaderFunc(loadFunc).Build()

From configuration:

conf := &scache.Config{
    Shards:       2,
    MaxSize:      4,
    Kind:         scache.scache.KindLRU,
    TTL:          time.Hour,
    ItemsToPrune: 10,
}

loadFunc := func(key interface{}) (val interface{}, err error) {
    val = key
    return
}

c, err := scache.FromConfig(conf).LoaderFunc(loadFunc).Build()

Benchmarks

The benchmarks can be found in page