GithubHelp home page GithubHelp logo

koajs / cash Goto Github PK

View Code? Open in Web Editor NEW
153.0 153.0 21.0 901 KB

HTTP response caching for Koa. Supports Redis, in-memory store, and more!

License: MIT License

JavaScript 100.00%
amazon aws cache caching cdn content delivery javascript koa memory network node redis s3 session sessions space static storage store

cash's People

Contributors

amitport avatar dependabot[bot] avatar edorivai avatar eknkc avatar greenkeeperio-bot avatar jonathanong avatar lbeschastny avatar nickmccurdy avatar niftylettuce avatar rek avatar shaunwarman avatar titanism avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cash's Issues

Supporting request method POST

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.

readme.usage needs updating

copypasta readme.usage doesnt work

options object has couple required props

cash/index.js

Line 34 in cafda56

if (!get) throw new Error('.get not defined');

// error

Error: .get not defined
at module.exports (.../node_modules/koa-cash/index.js:34:19)

Support Koa 2

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.

Cache headers

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.

Binary response support (application/octet-stream)

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

Cancel caching

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.