Tiny cache control header utility that parses human readable time strings into seconds.
Time based values use Template Literal Types to avoid passing invalid time string formats.
Installation
npm install cache-header-string
Usage
return new Response(..., {
headers: {
// sets cache control header to "public, max-age=604800, stale-while-revalidate=31536000"
'Cache-Control': cacheHeader({
public: true,
maxAge: '1week',
staleWhileRevalidate: '1year'
})
}
})
TimeString format
Any number followed by a timestring keyword:
ms
, milli
, millisecond
, milliseconds
- will parse to milliseconds
s
, sec
, secs
, second
, seconds
- will parse to seconds
m
, min
, mins
, minute
, minutes
- will parse to minutes
h
, hr
, hrs
, hour
, hours
- will parse to hours
d
, day
, days
- will parse to days
w
, week
, weeks
- will parse to weeks
mon
, mth
, mths
, month
, months
- will parse to months
y
, yr
, yrs
, year
, years
- will parse to years