Skip to content

Commit 5feb6bb

Browse files
committed
Update README
1 parent cf8b70c commit 5feb6bb

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ require "kemal-cache"
152152
153153
config = Kemal::Cache::Config.new(
154154
expires_in: 2.minutes,
155+
max_ttl: 10.minutes,
155156
ttl_resolver: ->(context : HTTP::Server::Context, key : String) { 2.minutes },
156157
cacheable_methods: ["GET"],
157158
cacheable_status_codes: [200, 202],
@@ -188,7 +189,8 @@ Use `expires_in` when every cached response should use the same TTL:
188189

189190
```crystal
190191
config = Kemal::Cache::Config.new(
191-
expires_in: 10.minutes
192+
expires_in: 10.minutes,
193+
max_ttl: 30.minutes
192194
)
193195
```
194196

@@ -197,12 +199,13 @@ Use `ttl_resolver` when the TTL should vary by route or resolved cache key:
197199
```crystal
198200
config = Kemal::Cache::Config.new(
199201
key_generator: ->(context : HTTP::Server::Context) { context.request.path },
202+
max_ttl: 5.minutes,
200203
ttl_resolver: ->(context : HTTP::Server::Context, key : String) do
201204
case key
202205
when "/homepage"
203206
30.seconds
204207
when "/catalog"
205-
5.minutes
208+
10.minutes
206209
else
207210
context.request.path.starts_with?("/api/") ? 15.seconds : nil
208211
end
@@ -212,8 +215,12 @@ config = Kemal::Cache::Config.new(
212215

213216
Returning `nil` falls back to `expires_in`.
214217

218+
When `max_ttl` is set, both `ttl_resolver` results and the `expires_in` fallback are clamped to that maximum.
219+
215220
Resolved TTL values must be positive.
216221

222+
`max_ttl`, when set, must also be positive.
223+
217224
### Methods And Status Codes
218225

219226
Opt in to additional HTTP methods:

0 commit comments

Comments
 (0)