Skip to content

admatic-tool/redis-middleware-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cache middleware for express.js

install:

$ npm install cache-middleware-redis

usage:

const app = require("express")()

const MiddlewareCache = require("middleware-cache")

const redisConfig = { 
  url: "redis://localhost",
  ttl: 2
}

const middlewareFactory = new MiddlewareCache(redisConfig) 


/* fake auth middleware that inject account_id in req props */
app.use((req, res, next) => {
  req.account_id = req.cookies.account_id
  next()
})


const middlewareConfig = { 
  useInKey: {
    reqProps: [ "account_id" ]
  }
}

/* to can get req.params */
app.use(middlewareFactory.middleware(middlewareConfig))

app.get("/ads/:id", (req, res) => {
	res.json({ date: new Date })
})

app.put("/ads/:id", (req, res) => {

  if(req.query.error)
    res.status(400).json({ ok: false })
  else
    res.json({ ok: true })
})

TODO

  • whitelist

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published