express-redis-cache icon indicating copy to clipboard operation
express-redis-cache copied to clipboard

Prefix in cache.route not being set

Open valedaemon opened this issue 9 years ago • 3 comments

Our app needs the ability to set a dynamic cache prefix. However, whenever I call cache.route({prefix: 'blah'}) and check what prefix is being utilized, it's always 'erc:'. How can I get cache.route to correctly set a prefix?

Thanks!

valedaemon avatar Nov 28 '16 18:11 valedaemon

I solved the issue by dynamically setting the name instead of a prefix. The fact that it doesn't seem possible to define the prefix from cache.route() appears to still be a bug, though.

valedaemon avatar Nov 29 '16 02:11 valedaemon

I got this working using this code:

var http = require('http');
var express = require('express');
var cache = require('express-redis-cache');

var app = express();
var cache = cache({
  prefix: 'test-prefix'
});

app.get('/test', cache.route(), function (req, res) {
  console.log('inside the test route');
  return res.status(200).json({ result: 'done' });
});

http.createServer(app).listen(8080, 'localhost', function(err) {
  if (err) { throw err; }
  console.log('Web server listening at http://localhost:8080');
});

Loading http://localhost:8080/test results in the db entry:

127.0.0.1:6379> keys *
1) "test-prefix:/test"

mjgs avatar Oct 05 '18 21:10 mjgs

Got the same bug :( Going with the same workaround.

iplanwebsites avatar May 28 '20 21:05 iplanwebsites