Skip to content
/ goche Public

Fast in-memory cache with TTL support and generics.

License

Notifications You must be signed in to change notification settings

romsar/goche

Repository files navigation

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.

About

Fast in-memory cache with TTL support and generics.

Resources

License

Stars

Watchers

Forks

Packages

No packages published