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

Support Koa 2 #27

Closed
felixsanz opened this issue Jul 13, 2016 · 5 comments
Closed

Support Koa 2 #27

felixsanz opened this issue Jul 13, 2016 · 5 comments

Comments

@felixsanz
Copy link

felixsanz commented Jul 13, 2016

This library doesn't have a @next tag? Only generators?

Also would be nice if the examples were a bit more clear. I can't still manage to get it working and documentation is not so friendly.

I think this works now with lru-cache because their API is like:

set(key, value, maxAge)
get(key) => value

Both of these will update the "recently used"-ness of the key. They do what you think. maxAge is optional and overrides the cache maxAge option if provided.

@stepankuzmin
Copy link

Hi there! I've solved it like this, and it seems to be working.

const cash = require('koa-cash');
const convert = require('koa-convert');
const LRU = require('lru-cache');

const cache = LRU(1000);
app.use(convert(cash({
  get: key => cache.get(key),
  set: (key, value) => cache.set(key, value)
})));

app.use(async (ctx, next) => {
  const cashed = await ctx.cashed();
  if (cashed) return;
  await next();
});

@joukosaastamoinen
Copy link

@lbeschastny I created a version with Koa 2 support: https://github.com/joukosaastamoinen/cash/tree/koa-2-support

If there was a branch for the next version, I could create a pull request.

@lbeschastny
Copy link
Contributor

@joukosaastamoinen I've created a next branch and pulled your code there.

I've also published it under next tag to npm.

Now all I need is a confirmation that it works fine with koa@2.

@joukosaastamoinen
Copy link

@lbeschastny I just took it into use in a small production app with Koa 2, and seems to work fine. I confirmed that responses are actually cached.

@adamlc
Copy link

adamlc commented Jan 3, 2018

Did we bin support for Koa 2?

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

No branches or pull requests

5 participants