Goche - it's fast, simple, zero dependency and well-tested Go package for create in-memory cache with generics.
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")
ctx := context.Background()
c := goche.New[string, string]()
go c.Run(ctx)
c.Set("foo", "bar", goche.TTL[string](10 * time.Second))
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.