koajs / cash Goto Github PK
View Code? Open in Web Editor NEWHTTP response caching for Koa. Supports Redis, in-memory store, and more!
License: MIT License
HTTP response caching for Koa. Supports Redis, in-memory store, and more!
License: MIT License
Any chance to support POST or the ability to configure supported methods with options?
I could do a PR, if you add me as a contributor.
copypasta readme.usage doesnt work
options object has couple required props
Line 34 in cafda56
// error
Error: .get not defined
at module.exports (.../node_modules/koa-cash/index.js:34:19)
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.
On my API I have a X-Total-Count header. How can I cache it? Is it interesting to have this feature on this library? If you agree it's a good idea, I can implement it and send a PR.
Hi there! It seems that cash doesn't support binary responses (like application/octet-stream
).
Eg. I'm trying to response with pbf like
ctx.body = Buffer.from(geobuf.encode(geojson, new Pbf()));
And getting
Error: Place koa-cache below any compression middleware.
;
My response headers are:
HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Type: application/octet-stream
Content-Length: 2227
Content-Encoding: identity
ETag: "8b3-CASiLhVb9Ldvy7npP1sNNQ"
Date: Fri, 09 Dec 2016 14:40:13 GMT
Connection: keep-alive
i.e. when response.body = ''
Hi!
According to the docs I should be able to pass maxAge
to yield* cashed(maxAge)
. However this does not seem to be the case, as my get function receives only two values.
I.e: Add a "methods" option which can be manually set and default it to HEAD and GET only.
I'm in a situation where, in general, I want a route to be cached. But sometimes I figure out on the way back through the middleware stack that I don't want it cached for this specific request.
To be a bit more precise: we have a situation where we need to poll for results, which can take up to 2 minutes. After the polling has completed, we cache those results for, say, 15 minutes. During this period after polling completion, we want any requests to this specific route to be cached.
A schematic solution could look like this:
app.use(cash( { ... } ));
app.use(async (ctx, next) => {
// In general I want all traffic beyond this middleware to be cached
if (await ctx.cached()) return;
return next();
});
app.use(async ctx => {
// fancyRenderLogic could determine that a specific response should not be cached
await fancyRenderLogic(ctx);
if (ctx.shouldNotCache) { // could be set by fancyRenderLogic
ctx.uncached(); // Or something like this where one could cancel
}
});
Please let me know what you think
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.