
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
Fast, efficient cache engines for both express routes cache & native node (redis, in-memory & file cache)
:rocket: Fast, efficient cache engines for expressJS & native nodeJS (redis, in-memory & file caching), singleton pattern make your application run smoothly like a boss.
npm install --save cache-all
or
yarn add cache-all
Init cache engine once and then you can use it anywhere, recommend init when booting your application
Example init in your server.js:
const express = require('express')
const cache = require('cache-all') // default is in-memory engine
// or
const cache = require('cache-all/memory') // explicit in-memory engine
// or
const cache = require('cache-all/file') // file engine
// or
const cache = require('cache-all/redis') // redis engine
const app = express()
// ...
cache.init({
ttl: 90,
})
// ...
app.listen(...)
Default config: Just config for engine that will be use
{
ttl: 90,
isEnable: true, // Flag for enable/disable cache, useful for development
}
{
ttl: 90,
isEnable: true,
file: {
path: path.join(process.cwd(), 'storage', 'cache') // Storage path for file cache engine
}
}
{
ttl: 90,
isEnable: true,
redis: {
port: 6379,
host: '127.0.0.1',
// password: 'yourpass',
// database: 0,
// prefix, // default is `cacheall:`
}
}
Set cache:
const cache = require('cache-all')
cache
.set('foo', 'bar')
.then(result => console.log(result))
Set cache with specific expire time (second):
const cache = require('cache-all')
cache
.set('foo', 'bar', 90)
.then(result => console.log(result)) // {status: 1}
Get cache (if key doesn't exist, null will be return):
const cache = require('cache-all')
cache
.get('foo')
.then(result => console.log(result)) // 'bar'
Get all cached entries as array:
const cache = require('cache-all')
cache
.getAll()
.then(result => console.log(result)) // [ { key: 'foo', value: 'bar'},... ]
Deprecated: should use cache.get and then check returned value instead use this function because costs of these functions is same.
Check if given key exist:
const cache = require('cache-all')
cache
.has('foo')
.then(result => console.log(result)) // true
Remove given cache key:
const cache = require('cache-all')
cache
.remove('foo')
.then(result => console.log(result)) // {status: 1}
Remove all cached data base on pattern/text:
const cache = require('cache-all')
await cache.set('user_foo', { name: 'foo' })
await cache.set('user_bar', { name: 'bar' })
await cache.removeByPattern('user') // or removeByPattern(/user/)
This package provide a middleware which will cache your response data base on request fullpath, request method and prefix (optinal).
NOTE: using prefix if you want manual clear data that was cached by middleware (using removeByPattern(prefix) method)
const express = require('express')
const router = express.Router()
const cache = require('cache-all')
router.get('/api/user', cache.middleware(86400, 'user'), function(req, res, next) {
res.json({foo: 'bar'})
})
// First time request '/foo' will cache response data before send back to client (non-blocking)
// Next time requests '/foo' will be response cached data immediately
You can use many cache engine together in your application, each engine still has singleton instance of it, that work independent with other
Just require specific engine you need instead require root
const fileCache = require('cache-all/file')
const memoryCache = require('cache-all/memory')
// ...
fileCache.init({
ttl: 60,
file: {
path: path.join(process.cwd(), 'storage', 'cache')
}
})
memoryCache.init({
ttl: 60,
})
// ...
app.listen(...)
const fileCache = require('cache-all/file')
const memoryCache = require('cache-all/memory')
fileCache
.set('foo', 'bar', 90)
.then(result => console.log(result)) // {status: 1}
memoryCache
.set('foo', 'bar', 90)
.then(result => console.log(result)) // {status: 1}
npm run test
You are welcome <3
| Version | Date | Description |
|---|---|---|
| 1.0.0 | 2019-01-14 | First version, contain basic functions |
| 1.1.0 | 2019-08-19 | Add removeByPattern function & update dependencies |
| 2.0.0 | 2019-09-05 | Re-structure (DRY) & remove mkdirp dependency |
| 2.0.1 | 2019-09-08 | Refactor FileStore - use ES6 class instead prototype |
| 2.0.2 | 2019-09-21 | Add getAll method & integrate travis-ci & code coverage |
| 2.0.6 | 2019-10-24 | Allow redis empty prefix PR#15 |
FAQs
Fast, efficient cache engines for both express routes cache & native node (redis, in-memory & file cache)
We found that cache-all demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.