LogoPly
Features

Cache

Manual per-request caching with TTL support.

Configure Manual Cache

Ply provides a manual caching system for storing responses or computed values in memory with a per-entry TTL (time to live).

Route-level automatic caching is no longer used. Caching is explicit through ctx.Cache.Memory.

Enable the cache

Initialize Ply with .WithCache():

app := ply.New().WithCache()

The option can be combined with other modules:

app := ply.New().WithCache().WithQueue().WithPubsub()

This creates a concurrency-safe in-memory TTL cache that handlers can use.

Example usage

func main() {
	app := ply.New().WithCache()

	app.Get("/", func(ctx *core.Context) {
		key := "my-key"
		val, found := ctx.Cache.Memory.Get(key)
		if found {
			fmt.Println("Cache hit:", key)
			ctx.Text(200, "From cache: "+string(val))
			return
		}

		fmt.Println("Cache miss:", key)
		result := "Hello, Ply!"
		ctx.Cache.Memory.Set(key, []byte(result), 10*time.Second)
		ctx.Text(200, "Generated: "+result)
	})

	app.RunServer(":8080")
}

How it works

  • Each request has access to ctx.Cache.Memory, a concurrency-safe in-memory TTL cache.
  • The handler decides what to store, when it expires and how it is read.
  • Without automatic route caching, any value can be cached: computed data, responses or results from external calls.

Use cases

  • Caching database or external API responses per request
  • Storing computed results temporarily
  • Reducing repeated work on high-traffic endpoints