Last active
May 14, 2026 15:39
-
-
Save thegulshankumar/5e8ceac94aafebcf20ced4a6a8a59a2d to your computer and use it in GitHub Desktop.
CacheTube Edge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| async fetch(request, env, ctx) { | |
| const cache = caches.default; | |
| const cacheKey = new Request(request.url, request); | |
| let response = await cache.match(cacheKey); | |
| if (response) { | |
| return response; | |
| } | |
| // Example Channel: Google Developers | |
| // Channel ID: UC_x5XG1OV2P6uZZ5FSM9Ttw | |
| const youtubeFeed = | |
| 'https://www.youtube.com/feeds/videos.xml?channel_id=UC_x5XG1OV2P6uZZ5FSM9Ttw'; | |
| response = await fetch(youtubeFeed, { | |
| cf: { | |
| cacheTtl: 1800, | |
| cacheEverything: true | |
| }, | |
| headers: { | |
| 'User-Agent': 'Cloudflare Worker' | |
| } | |
| }); | |
| response = new Response(response.body, response); | |
| response.headers.set( | |
| 'Content-Type', | |
| 'application/xml; charset=UTF-8' | |
| ); | |
| response.headers.set( | |
| 'Cache-Control', | |
| 'public, max-age=0' | |
| ); | |
| response.headers.set( | |
| 'X-Robots-Tag', | |
| 'noindex, nofollow' | |
| ); | |
| ctx.waitUntil( | |
| cache.put(cacheKey, response.clone()) | |
| ); | |
| return response; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup steps: