-
Notifications
You must be signed in to change notification settings - Fork 1.4k
update the age header when responding from cache #15052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a625945
faa3628
457a47f
536dffa
f7513a9
f3dcb37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "miniflare": patch | ||
| --- | ||
|
|
||
| Increment the Age response header when responding from cache. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ interface CacheMetadata { | |
| headers: string[][]; | ||
| status: number; | ||
| size: number; | ||
| stored?: number; | ||
| } | ||
|
|
||
| type CacheRouteHandler = RouteHandler< | ||
|
|
@@ -302,6 +303,12 @@ export class CacheObject extends MiniflareDurableObject { | |
| // time we don't do this is when the entry isn't found, or expired, in which | ||
| // case, we just threw a `CacheMiss`) | ||
| assert(resHeaders !== undefined); | ||
| const now = this.timers.now(); | ||
| const age = parseInt(resHeaders.get("age") || "0", 10); | ||
| const cachedDuration = Math.round( | ||
| (now - (cached.metadata.stored || now)) / 1000 | ||
| ); | ||
| resHeaders.set("Age", String(age + cachedDuration)); | ||
| resHeaders.set("CF-Cache-Status", "HIT"); | ||
| resRanges ??= []; | ||
|
|
||
|
|
@@ -356,6 +363,7 @@ export class CacheObject extends MiniflareDurableObject { | |
| headers: Object.entries(headers), | ||
| status: res.status, | ||
| size, | ||
| stored: this.timers.now(), | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Cached responses can report an age that is too young for slow or large uploads The time a cached item was saved is recorded ( Why the timestamp lands late: metadata promise resolves after the blob write
Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| })); | ||
|
|
||
| await this.storage.put({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some more details to this changeset so it makes it a bit clearer on the change and what it actually fixes.