evanshortiss / expeditious

caching interface for node.js with support for multiple storage engines
MIT License
7 stars 5 forks source link

Problems with opt.defaultTtl #6

Closed carvalhoviniciusluiz closed 6 years ago

carvalhoviniciusluiz commented 6 years ago

Hello I'm trying to use the expeditious. She's asking for opts.defaultTtl Follows an image..

captura de tela 2017-11-17 as 21 53 08

How can I solve this? To try to solve I passed the keys to the express-expeditious this way

var expressCache = require('express-expeditious')({
  namespace: 'expresscache',
  expeditious: cache,
  statusCodeExpires: {
    500: (30 * 1000),
    502: (60 * 1000)
  },
  defaultTtl: '2 minute'
})

then the following message appears in the terminal

express-expeditious: You did not supply an "engine". Defaulting to expeditious-engine-memory. Beware that this can result in high memory usage for the node process if not used carefully

I do not know how to solve :{

evanshortiss commented 6 years ago

@carvalhoviniciusluiz it looks like you are trying to use this for express caching? I created a test using the code below so and it seems to be working so maybe try that with the latest version of the module.

// This works fine using the latest "expeditious" module
const instance = expeditious({
  engine: require('expeditious-engine-memory')(),
  defaultTtl: 120 * 1000,
  namespace: 'hello'
})

To fix the warning in your own code try this:

var expressCache = require('express-expeditious')({
  namespace: 'expresscache',
  // Changed "expeditious" to "engine"
  engine: cache,
  statusCodeExpires: {
    500: (30 * 1000),
    502: (60 * 1000)
  },
  defaultTtl: '2 minute'
})

Here's the fastest way to setup some express caching - you can remove some of the extra code you have since it's no longer required. It will print a warning, but you can ignore it if your application is not going to be deployed to a large user base.

const app = require('express')()
const cache = require('express-expeditious')({
  defaultTtl: 120 * 1000,
  namespace: 'testing'
})

app.use(cache)

app.get('/', (req, res, next) => {
  setTimeout(() => {
    res.end('ok')
  }, 2000)
})

app.listen(3000, (err) => {
  if (err) throw err;

  console.log('listening on 3000')
})

Let me know if this helps.

evanshortiss commented 6 years ago

@carvalhoviniciusluiz closing this since I cannot replicate in latest versions. Reopen if necessary.