mjackson / remix-the-web

Open source tools for Remix (or any framework!)
MIT License
712 stars 14 forks source link

feature: Cache-Control header #6

Closed alexanderson1993 closed 2 months ago

alexanderson1993 commented 3 months ago

I propose the same interface as pretty-cache-header, with a class for the cache control header that includes all of the available directives as properties. Optionally, allowing time strings in addition to numbers would be great, eg. "1hour" === 3600

This feature does request does not include ETag/If-None-Match/If-Modified-Since. Just the Cache-Control header

Example:

let headers = new Headers();

headers.cacheControl = "public, max-age=604800, s-maxage=3600"
console.log(headers.cacheControl.public) // true
console.log(headers.cacheControl.maxAge) // 604800

// Optionally use time strings where appropriate
headers.cacheControl.maxAge = "1hour"

console.log(headers.get('Cache-Control')) // "public, max-age=3600, s-maxage=3600"
alexanderson1993 commented 3 months ago

I intend to start implementing this myself. Hopefully I can get a PR in the next few days. Just wanted to get it on your radar in case you don't love the implementation.