All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Workers - Requests made from Cloudflare Workers can now force a revalidation of their cache with the origin

11mo ago

Source

CloudflareWorkers - Requests made from Cloudflare Workers can now force a revalidation of their cache with the origincloudflare.com
Snippet from the RSS feed
By setting the value of the cache property to no-cache , you can force Cloudflare's cache to revalidate its contents with the origin when making subrequests from Cloudflare Workers . JavaScript export default { async fetch ( req , env , ctx ) { const request = new Request ( " , { cache : "no-cache" , } ) ; const response = await fetch ( request ) ; return response ; }, }; TypeScript export default { async fetch ( req , env , ctx ) : Promise < Response > { const request = new Request ( " , { cache : 'no-cache' } ) ; const response = await fetch ( request ) ; return response ; } } satisfies ExportedHandler < Environment > When no-cache is set, the Worker request will first look for a match in Cloudflare's cache, then: If there is a match, a conditional request is sent to the origin, regardless of whether or not the match is fresh or stale. If the resource has not changed, the cached version is returned. If the resource has changed, it will be downloaded from the origin, updated in the cache, and returned. If there is no match, Workers will make a standard request to the origin and cache the response. This increases compatibility with NPM packages and JavaScript frameworks that rely on setting the cache property, which is a cross-platform standard part of the Request interface. Previously, if you set the cache property on Request to 'no-cache' , the Workers runtime threw an exception. Learn how the Cache works with Cloudflare Workers Enable Node.js compatibility for your Cloudflare Worker Explore Runtime APIs and Bindings available in Cloudflare Workers

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.