Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis cached data for the same key is never returned, only continuously added on subsequent requests #246

Open
victorbadila opened this issue Apr 13, 2022 · 2 comments

Comments

@victorbadila
Copy link

I have the following:

  const client = redis.createClient({ url: 'redis url...' });
  const cacheWithRedis = apicache.options({
    debug: true,
    redisClient: client,
  }).middleware;


app.get('*', 
    cacheWithRedis('1 day', () => true),
    (req, res) => {
      console.log('post cache, rendering html');
      res.render(someHtmlFile);
    }

When I run consecutive requests against the server for the same url I always get duplicates of the add to cache logs, but the cached result is never returned.

[apicache] adding cache entry for "/my-url" @ 1 day - 1.92sec
[apicache] _apicache.headers: 
[apicache] res.getHeaders():  [Object: null prototype] {
  'x-powered-by': 'Express',
  'content-type': 'text/html; charset=utf-8',
  'content-length': '293611',
  etag: 'W/"47aeb-2ew9IPOkaA3owFUD/RU5VqJ4Vrk"'
}
[apicache] cacheObject:  {
  status: 200,
  headers: {
    'x-powered-by': 'Express',
    'content-type': 'text/html; charset=utf-8',
    'content-length': '293611',
    etag: 'W/"47aeb-2ew9IPOkaA3owFUD/RU5VqJ4Vrk"'
  },
  data: <Buffer 3c 21 44 4f 43 54 59 50 45 20 68 74 6d 6c 3e 3c 68 74 6d 6c 20 6c 61 6e 67 3d 22 65 6e 22 3e 3c 68 65 61 64 3e 3c 6c 69 6e 6b 20 72 65 6c 3d 22 70 72 ... 293[apicache] res.getHeaders():  [Object: null prototype] {
}
[apicache] adding cache entry for "/my-url" @ 1 day - 2.75sec
[apicache] _apicache.headers: 
[apicache] res.getHeaders():  [Object: null prototype] {
  'x-powered-by': 'Express',
  'content-type': 'text/html; charset=utf-8',
  'content-length': '293611',
  etag: 'W/"47aeb-2ew9IPOkaA3owFUD/RU5VqJ4Vrk"'
}
[apicache] cacheObject:  {
  status: 200,
  headers: {
    'x-powered-by': 'Express',
    'content-type': 'text/html; charset=utf-8',
    'content-length': '293611',
    etag: 'W/"47aeb-2ew9IPOkaA3owFUD/RU5VqJ4Vrk"'
  },
  data: <Buffer 3c 21 44 4f 43 54 59 50 45 20 68 74 6d 6c 3e 3c 68 74 6d 6c 20 6c 61 6e 67 3d 22 65 6e 22 3e 3c 68 65 61 64 3e 3c 6c 69 6e 6b 20 72 65 6c 3d 22 70 72 ... 293561 more bytes>,
  encoding: undefined,
  timestamp: 1649866135.151
}

...etc

I have the cache middleware second function return true all the time, but it always goes to the next middleware which actually renders the html on the server and sends it back. Am I missing anything?

@pballester
Copy link

Hello @victorbadila !

What version of redis package are you using?

Currently apicache it's not compatible with redis 4 and I think that could be the problem.

Regards

@SarkarKurdish
Copy link

Same issue here i've downgrade my redis to 4.0.0 the issue is still there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants