Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


HTTP response caching for Koa

Subscribe to updates I use cash

Statistics on cash

Number of watchers on Github 88
Number of open issues 6
Average time to close an issue 29 days
Main language JavaScript
Average time to merge a PR 5 days
Open pull requests 17+
Closed pull requests 21+
Last commit about 2 years ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 47 KB
Organization / Authorkoajs
Page Updated
Do you use cash? Leave a review!
View open issues (6)
View cash activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating cash for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Koa Cash

NPM version Build status Test coverage Dependency Status License Downloads

HTTP response caching for Koa. Caches the response based on any arbitrary store you'd like.

  • Handles JSON and stream bodies
  • Handles gzip compression negotiation
  • Handles 304 responses
  // some options

app.use(function* (next) {
  // this response is already cashed if `true` is returned,
  // so this middleware will automatically serve this response from cache
  if (yield this.cashed()) return

  // set the response body here,
  // and the upstream middleware will automatically cache it
  this.response.body = 'hello world!'



Options are:


Default max age (in milliseconds) for the cache if not set via yield this.cashed(maxAge).


Minimum byte size to compress response bodies. Default 1kb.


A hashing function. By default, it's:

function hash(_this) {
  return this.request.url

this is the Koa context and is also passed as an argument. By default, it caches based on the URL.


Get a value from a store. Must return a yieldable, which returns the cache's value, if any.

function get(key, maxAge) {
  return <yieldable>

Note that all the maxAge stuff must be handled by you. This module makes no opinion about it.


Set a value to a store. Must return a yieldable.

function set(key, value, maxAge) {
  return <yieldable>

Note: maxAge is set by .cash={ maxAge }. If it's not set, then maxAge will be 0, which you should then ignore.


Using a library like lru-cache, though this would not quite work since it doesn't allow per-key expiration times.

var cache = require('lru-cache')({
  maxAge: 30000 // global max age

  get (key, maxAge) {
    return cache.get(key)
  set (key, value) {
    cache.set(key, value)

var cached = yield this.cashed([maxAge])

This is how you enable a route to be cached. If you don't call yield this.cashed(), then this route will not be cached nor will it attempt to serve the request from the cache.

maxAge is the max age passed to get().

If cached is true, then the current request has been served from cache and you should early return. Otherwise, continue setting this.response.body= and this will cache the response.


  • Only GET and HEAD requests are cached.
  • Only 200 responses are cached. Don't set 304 status codes on these routes - this middleware will handle it for you
  • The underlying store should be able to handle Date objects as well as Buffer objects. Otherwise, you may have to serialize/deserialize yourself.
cash open issues Ask a question     (View All Issues)
  • over 3 years Support Koa 2
  • almost 4 years make sure we support empty bodies
  • almost 4 years increase test coverage to 100%
  • almost 4 years Supporting request method POST
cash open pull requests (View All Pulls)
  • Update supertest to version 2.0.1 🚀
  • Update mocha to version 3.1.2 🚀
  • Update standard to version 8.4.0 🚀
  • Update mocha to version 3.1.1 🚀
  • Update standard to version 8.3.0 🚀
  • Update mocha to version 3.1.0 🚀
  • Update standard to version 8.2.0 🚀
  • Update standard to version 8.1.0 🚀
  • Update standard to version 8.0.0 🚀
  • Update mocha to version 3.0.2 🚀
  • Update mocha to version 3.0.0 🚀
  • Update supertest to version 2.0.0 🚀
  • Support deflate
  • Next
  • Update standard to version 9.0.0 🚀
  • Update koa to version 2.0.1 🚀
  • Update supertest to version 3.0.0 🚀
cash questions on Stackoverflow (View All Questions)
  • Magento Cash on Delivery Extra Fee
  • virtocommerce Cash on Delivery payment
  • Magento cash on delivery payment
  • how to do cash on delivery in rails 4 application?
  • netsuite transform a sales order to cash sale
  • a cash register object that simulates a real life cash register - Java
  • OpenCart : How can range Cash On Delivery money
  • Set Payment Method "Cash On Delivery" on Particular State Only
  • Working with cash in Java (SOLVED)
  • Calculate different order status count and total cash for each order status in Woocommerce
  • How to enable cash Control Option in Odoo 9
  • SQL, cash totals for each SKU
  • Laravel's Elixir asset cash/versioning does not load appropriate file
  • Square Cash Label Animation
  • Chrome cash values in inputs
  • Cash Register Change Issue
  • All cash change is only for one bill
  • How to disable Cash on Delivery for Downloadable products on Opencart
  • MySql - Error Code: 1242 / Splitting table fields into two column "cash book" using SELECT Statement
  • Non-Mandatory Location Field on Cash Sales in NetSuite
  • ATM daily Cash forecasting
  • cash reg loading individual words from each line into the different struct members
  • Magento adding Cash on Delivery fee when user select paypal
  • USAePay Payment Gateway - Refund cash from Merchant account to Customer account
  • open cash drawer with TMT-T81 epson iOS SDK
  • How to open cash box more than once in a little time?
  • Cash on delivery payment method should visible only for some zip codes/pin codes in magento
  • How to get data about a company's financials, balance sheet, cash flow, etc. via its ticker symbol
  • open cash drawer with php_printer.dll library PHP
  • How to restrict cash on delivery to specific states in Magnento
cash list of languages used
Other projects in JavaScript