Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

add cache behavior modifiers to RequestInit interface #17

Merged
merged 3 commits into from
May 15, 2020

Conversation

trjstewart
Copy link
Contributor

Documentation for these features can be found here , under the Overriding TTL and Override based on origin response code headings.

// Force response to be cached for 300 seconds.
fetch(event.request, { cf: { cacheTtl: 300 } })

// Force response to be cached for 86400 seconds for 200 status codes, 1 second for 404, and do not cache 500 errors
fetch(request, { cf: { cacheTtlByStatus: { '200-299': 86400, '404': 1, '500-599': 0 } } })

index.d.ts Outdated
@@ -5,6 +5,8 @@ interface FetchEvent {
interface RequestInit {
cf?: {
cacheEverything?: boolean
cacheTtl?: number
cacheTtlByStatus?: { [key: string]: number }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be a good idea and add some comments on how to use this DSL. Show an @example of the range syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are examples in the provided Cloudflare documentation. Or do you mean add examples to the readme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrf0110 just bumping for some clarification please.

Copy link
Contributor

@ispivey ispivey May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he meant examples inline in the comments, like some of the other fields have. While it’s duplicative of the docs, this will ensure IDEs provide helpful documentation directly in your editor. We’d also like to auto-generate docs from these comments eventually.

Also, I recently merged a refactor that creates a conflict. You’ll want to put these on the new CfRequestInit interface, now, if you can rebase on master.

If you think you can update that sometime today or tomorrow, let us know — I’d love to include this in a 1.0.10 release on Friday.

Also happy to do that ourselves if you don’t have time!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ispivey I should have time to do it today, if it's not done in the next 12 hours feel free to do so yourself if you have the time. Thanks heaps for the comment!

@trjstewart
Copy link
Contributor Author

@ispivey I've added those examples if you're happy with that.

@ispivey
Copy link
Contributor

ispivey commented May 15, 2020

Thanks, and thanks so much for contributing!

@ispivey ispivey merged commit f9fa52a into cloudflare:master May 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants