boring-avatars-service icon indicating copy to clipboard operation
boring-avatars-service copied to clipboard

Increase max-age when set name.

Open H4ad opened this issue 3 years ago • 0 comments
trafficstars

Is your feature request related to a problem? Please describe.

I've seen you set cache-control: s-max-age=1: https://github.com/hihayk/boring-avatars-service/blob/1cf355b12ec0aa3b2be284641da32ec1105b55ab/api/index.js#L38

But it only lasts for a second, so I experienced a lot of cache misses.

From what I can see, the boring avatar is the same if we specify name. So the cache-control for when the user sends name should be high.

Describe the solution you'd like

Increase the cache control to something like a day or a week. In express, is something like:

// only cache if name is passed.
if (req.query.name || req.params.name) {
  // ref: https://vercel.com/docs/concepts/functions/serverless-functions/edge-caching#recommended-cache-control
  res.setHeader('Cache-Control', 'max-age=0, s-maxage=86400');
} else {
  res.setHeader('Cache-control', 'max-age=0, s-max-age=1');
}

H4ad avatar Oct 08 '22 23:10 H4ad