Skip to content
Kevin Burns edited this page Oct 2, 2019 · 6 revisions

TTL specifies a default expiration time for cached responses. When the global ttl is set to 10 seconds, the expiration time for any cacheable response will be set to 10 seconds in the future by default.

Config Parameter: TTL

microcache.New(microcache.Config{
	TTL: 10 * time.Second,
})

The default ttl can be overridden on a per-request basis with the response header microcache-ttl (seconds)

w.Header().Set("microcache-ttl", "10")

The default ttl is 0, meaning that your app must explicitly respond with a ttl header in order for the response to be considered fresh for any period of time.

A ttl of 0 may still be useful, as it can be combined with stale-while-revalidate to serve many concurrent requests while polling serially to update hot items in the background.

Config Parameter TTL time.Duration
Response Header microcache-ttl int (seconds)
Default 0
Recommended 10s
Clone this wiki locally