Skip to content

Caching

cache.Module(cache.Options{TTL: time.Minute}) // Store defaults to an in-memory LRU
u, err := cache.GetOrSet(ctx, c, "user:"+id, 0, func(ctx context.Context) (*User, error) { return repo.Find(ctx, id) })
r = r.Use(dygo.Interceptors(dygo.Ref[*cache.Interceptor]()))
r.Get("/products", dygo.Handle(c.List), cache.TTL(30*time.Second))
r.Get("/live", dygo.Handle(c.Live), cache.NoCache())
byID := cache.Wrap(c, "user", time.Minute, users.ByID) // a cached func(ctx, string) (*User, error)

Values are stored as JSON. Implement cache.Store (three methods) for Redis or another backend.