{"id":15297100,"url":"https://github.com/bahung1221/cache-all","last_synced_at":"2025-10-12T11:42:23.270Z","repository":{"id":56016032,"uuid":"165667550","full_name":"bahung1221/cache-all","owner":"bahung1221","description":"Fast, efficient cache engines for both express routes \u0026 native nodeJs (redis, in-memory \u0026 file cache)","archived":false,"fork":false,"pushed_at":"2022-10-12T06:51:32.000Z","size":229,"stargazers_count":21,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T13:04:51.037Z","etag":null,"topics":["cache","cache-storage","cachemanager","filecache","memcached","node","node-module","nodejs","rediscache","singleton"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahung1221.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-14T13:36:26.000Z","updated_at":"2025-02-14T21:05:20.000Z","dependencies_parsed_at":"2022-08-15T11:30:59.469Z","dependency_job_id":null,"html_url":"https://github.com/bahung1221/cache-all","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahung1221%2Fcache-all","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahung1221%2Fcache-all/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahung1221%2Fcache-all/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahung1221%2Fcache-all/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahung1221","download_url":"https://codeload.github.com/bahung1221/cache-all/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790737,"owners_count":21162082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-storage","cachemanager","filecache","memcached","node","node-module","nodejs","rediscache","singleton"],"created_at":"2024-09-30T19:15:09.684Z","updated_at":"2025-10-12T11:42:18.235Z","avatar_url":"https://github.com/bahung1221.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/cache-all.svg)](https://www.npmjs.com/package/cache-all)\n[![Dependency Status](https://david-dm.org/bahung1221/cache-all.svg)](https://david-dm.org/bahung1221/cache-all)\n[![Build Status](https://travis-ci.com/bahung1221/cache-all.svg?branch=master)](https://travis-ci.com/bahung1221/cache-all)\n[![Coverage Status](https://coveralls.io/repos/github/bahung1221/cache-all/badge.svg?branch=master)](https://coveralls.io/github/bahung1221/cache-all?branch=master)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ac857033d0e4472e9e9b5176a7c72fc4)](https://www.codacy.com/manual/bahung1221/cache-all?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=bahung1221/cache-all\u0026amp;utm_campaign=Badge_Grade)\n\n[![NPM info](https://nodei.co/npm/cache-all.png?downloads=true)](https://www.npmjs.com/package/cache-all)\n\n# cache-all\n:rocket: Fast, simple cache engines for expressJS \u0026 native nodeJS (redis, in-memory \u0026 file caching).\n\n- Multi cache engines, each engine has one singleton instance and independent with other engine.\n- Include express middleware, which can be use for cache response on specific routes.\n- Init once and then use anywhere for caching anything in your application.\n\n## Install\n```\nnpm install --save cache-all\n```\nor\n```\nyarn add cache-all\n```\n\n## Usages (single cache engine):\n### Init\nInit cache engine once and then you can use it anywhere,\nrecommend init when booting your application\n\nExample init in your server.js:\n```javascript\nconst express = require('express')\nconst cache = require('cache-all') // default is in-memory engine\n// or\nconst cache = require('cache-all/memory') // explicit in-memory engine\n// or\nconst cache = require('cache-all/file') // file engine\n// or\nconst cache = require('cache-all/redis') // redis engine\nconst app = express()\n\n// if you need to use cache methods immediately after init method, you must await it `await cache.init({...})`\ncache.init({\n  ttl: 90,\n})\n// ...\n\napp.listen(...)\n```\n\nDefault config:\nJust config for engine that will be use\n\n- in-memory\n```javascript\n{\n  ttl: 90,\n  isEnable: true, // Flag for enable/disable cache, useful for development\n}\n```\n\n- file\n```javascript\n{\n  ttl: 90,\n  isEnable: true,\n  file: {\n    path: path.join(process.cwd(), 'storage', 'cache') // Storage path for file cache engine\n  }\n}\n```\n\n- redis\n```javascript\n{\n  ttl: 90,\n  isEnable: true,\n  redis: {\n    port: 6379,\n    host: '127.0.0.1',\n    // password: String,\n    // database: String,\n    // prefix: String, // default is `cacheall:`\n    // setex: Function\n  }\n}\n```\n\n### set(key, value, [expireIn])\nSet cache:\n```javascript\nconst cache = require('cache-all')\n\ncache\n  .set('foo', 'bar')\n  .then(result =\u003e console.log(result))\n```\n\nSet cache with specific expire time (second):\n```javascript\nconst cache = require('cache-all')\n\ncache\n  .set('foo', 'bar', 90)\n  .then(result =\u003e console.log(result)) // {status: 1}\n```\n\n### get(key)\nGet cache (if key doesn't exist, null will be return):\n```javascript\nconst cache = require('cache-all')\n\ncache\n  .get('foo')\n  .then(result =\u003e console.log(result)) // 'bar'\n```\n\n### getAll()\nGet all cached entries as array:\n```javascript\nconst cache = require('cache-all')\n\ncache\n  .getAll()\n  .then(result =\u003e console.log(result)) // [ { key: 'foo', value: 'bar'},... ]\n```\n\n### has(key)\n**Deprecated**: should use `cache.get` and then check returned value instead use this function because costs of these functions is same.\n\nCheck if given key exist:\n```javascript\nconst cache = require('cache-all')\n\ncache\n  .has('foo')\n  .then(result =\u003e console.log(result)) // true\n```\n\n### remove(key)\nRemove given cache key:\n```javascript\nconst cache = require('cache-all')\n\ncache\n  .remove('foo')\n  .then(result =\u003e console.log(result)) // {status: 1}\n```\n\n### removeByPattern(pattern)\nRemove all cached data base on pattern/text:\n```javascript\nconst cache = require('cache-all')\n\nawait cache.set('user_foo', { name: 'foo' })\nawait cache.set('user_bar', { name: 'bar' })\n\nawait cache.removeByPattern('user') // or removeByPattern(/user/)\n```\n\n### middleware([expireIn], [prefix]) (Cache on express route)\nThis package provide a middleware which will cache your response data\nbase on request fullpath, request method and prefix (optinal).\n\n**NOTE**: using prefix if you want manual clear data that was cached by middleware (using `removeByPattern(prefix)` method)\n\n```javascript\nconst express = require('express')\nconst router = express.Router()\nconst cache = require('cache-all')\n\nrouter.get('/api/user', cache.middleware(86400, 'user'), function(req, res, next) {\n  res.json({foo: 'bar'})\n})\n// First time request '/foo' will cache response data before send back to client (non-blocking)\n// Next time requests '/foo' will be response cached data immediately\n```\n\n## Usages (multi engine)\nYou can use many cache engine together in your application, each engine still has\nsingleton instance of it, that work independent with other\n\nJust require specific engine you need instead require root\n- init\n```javascript\nconst fileCache = require('cache-all/file')\nconst memoryCache = require('cache-all/memory')\n\n// ...\nfileCache.init({\n  ttl: 60,\n  file: {\n    path: path.join(process.cwd(), 'storage', 'cache')\n  }\n})\nmemoryCache.init({\n  ttl: 60,\n})\n// ...\n\napp.listen(...)\n```\n\n- set/get/has/remove/middleware\n```javascript\nconst fileCache = require('cache-all/file')\nconst memoryCache = require('cache-all/memory')\n\nfileCache\n  .set('foo', 'bar', 90)\n  .then(result =\u003e console.log(result)) // {status: 1}\n  \nmemoryCache\n  .set('foo', 'bar', 90)\n  .then(result =\u003e console.log(result)) // {status: 1}\n```\n\n## Typescript\nAdd `@types/express` and `@type/redis` as devDependencies:\n```\nyarn add -D @types/express @types/redis\n```\nThat's it!\n\n## Test\n```\nnpm run test\n```\n\n## TODO\n- Mongo cache engines\n- Reduce number of dependencies\n- Update Code coverage\n- Event\n\n## Contributes\nYou are welcome \u003c3\n\n## Release Note\n|Version|Date|Description|\n|:--:|:--:|:--|\n|1.0.0|2019-01-14|First version, contain basic functions|\n|1.1.0|2019-08-19|Add removeByPattern function \u0026 update dependencies|\n|2.0.0|2019-09-05|Re-structure (DRY) \u0026 remove `mkdirp` dependency |\n|2.0.1|2019-09-08|Refactor FileStore - use ES6 class instead prototype|\n|2.0.2|2019-09-21|Add `getAll` method \u0026 integrate travis-ci \u0026 code coverage|\n|2.0.6|2019-10-24|Allow redis empty prefix [PR#15](https://github.com/bahung1221/cache-all/pull/15)|\n|2.0.8|2019-10-28|FS async implementation [PR#19](https://github.com/bahung1221/cache-all/pull/19)|\n|2.1.0|2019-10-28|Add type definition (typescript) [PR#22](https://github.com/bahung1221/cache-all/pull/22)|\n|2.1.1|2020-08-05|Upgrade node-redis to `v3` (Removed hiredis completely)|\n\n## License\nThis project is licensed under the terms of the [MIT](https://github.com/bahung1221/cache-all/blob/master/LICENSE) license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahung1221%2Fcache-all","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahung1221%2Fcache-all","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahung1221%2Fcache-all/lists"}