Skip to content

Commit d71ee79

Browse files
committed
Cache docs
1 parent 29fb196 commit d71ee79

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ let data = try await fetch(req, origin: "https://httpbin.org", .options(
136136
))
137137
try await res.proxy(data)
138138
```
139+
140+
## Cache
141+
142+
The Compute package provdes access to [Fastly's Cache API](https://developer.fastly.com/learning/concepts/edge-state/cache#simple-cache) allowing you to cache and retrieve arbitrary data during a request:
143+
144+
145+
```swift
146+
let data = try await Cache.getOrSet("my-page") {
147+
let res = try await expensivePageRender()
148+
return (res, .ttl(60))
149+
}
150+
151+
try await res
152+
.status(200)
153+
.header(.contentLength, "\(data.contentLength)")
154+
.send(data.body)
155+
```

0 commit comments

Comments
 (0)