Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 1.39 KB

README.md

File metadata and controls

56 lines (39 loc) · 1.39 KB

Goche

Goche - it's fast, simple, zero dependency and well-tested Go package for create in-memory cache with generics.

Go Report Card

mr goche

Benchmarks

benchmarks

Usage

Basic

ctx := context.Background()
c := goche.New[string, string](
    // goche.WithPollInterval[string, string](3 * time.Second),
    // goche.WithSize[string, string](5),
    // goche.WithValues[string, string](map[string]string{"foo":"bar"}),
    // goche.WithDefaultTTL[string, string](5 * time.Second),
)
go c.Run(ctx)

c.Set("foo", "bar")

val, ok := c.Get("foo") // val == "bar"
if !ok {
    fmt.Println("not found!")
}

c.Delete("foo")

TTL

ctx := context.Background()
c := goche.New[string, string]()
go c.Run(ctx)

c.Set("foo", "bar", goche.TTL[string](10 * time.Second))

TTL with reset

ctx := context.Background()
c := goche.New[string, string]()
go c.Run(ctx)

c.Set("foo", "bar", goche.TTLWithReset[string](10 * time.Second))

// now, everytime when we do c.Get - ttl is resetting.