Skip to content

Instantly share code, notes, and snippets.

@standinga
Created August 23, 2020 01:27
Show Gist options
  • Save standinga/d18ff10c5c122eb80df68476da6d20d1 to your computer and use it in GitHub Desktop.
Save standinga/d18ff10c5c122eb80df68476da6d20d1 to your computer and use it in GitHub Desktop.
const express = require('express')
const app = express()
const port = 3000
const increment = function () {
counter ++
setTimeout(increment, 1000);
}
var maxAge = 4
increment()
var counter = 0
app.get('*', (req, res) => {
console.log(`Counter: ${counter}, request cache policy: ${req.headers['cache-policy']}`)
res.set('Cache-Control', `public, max-age=${maxAge}`)
res.set(`Etag`, `${Math.floor(counter / 2)}`)
res.send(`Counter: ${counter}`)
})
app.listen(port, ()=> console.log(`listening at http://0.0.0.0:${port}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment