{"id":13394339,"url":"https://github.com/vaneenige/unvault","last_synced_at":"2025-04-23T00:43:40.210Z","repository":{"id":57386967,"uuid":"118670851","full_name":"vaneenige/unvault","owner":"vaneenige","description":"📦 A minimal layer for node that allows results of time-consuming tasks to be stored.","archived":false,"fork":false,"pushed_at":"2018-03-23T11:15:37.000Z","size":29,"stargazers_count":61,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T00:43:32.029Z","etag":null,"topics":["api","automated","node","responses","routing","server","store"],"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/vaneenige.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":"2018-01-23T21:16:05.000Z","updated_at":"2023-06-10T07:18:19.000Z","dependencies_parsed_at":"2022-09-15T02:52:04.382Z","dependency_job_id":null,"html_url":"https://github.com/vaneenige/unvault","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaneenige%2Funvault","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaneenige%2Funvault/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaneenige%2Funvault/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaneenige%2Funvault/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaneenige","download_url":"https://codeload.github.com/vaneenige/unvault/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250348884,"owners_count":21415907,"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":["api","automated","node","responses","routing","server","store"],"created_at":"2024-07-30T17:01:16.438Z","updated_at":"2025-04-23T00:43:40.188Z","avatar_url":"https://github.com/vaneenige.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003ch1\u003eUnvault\u003c/h1\u003e\n\nUnvault is a minimal layer for node that allows results of time-consuming tasks to be stored. Improved performance is achieved by adding trackers that periodically update the layer, so that stored responses can be served instantly once requested. Also available as [middleware](https://github.com/vaneenige/unvault-middleware).\n\n\u003ca href=\"https://www.npmjs.org/package/unvault\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/unvault.svg?style=flat\" alt=\"npm\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://travis-ci.org/vaneenige/unvault\"\u003e\n  \u003cimg src=\"https://travis-ci.org/vaneenige/unvault.svg?branch=master\" alt=\"travis\"\u003e\n\u003c/a\u003e\n\n#### Features:\n\n* Insert key based trackers\n* Automatic and manual update\n* Support for `async` and `await`\n* Fast (without dependencies)\n* Small wrapper extending [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)\n* Support for multiple stores\n\n## Install\n\n```\n$ npm install --save unvault\n```\n\n\u003e **Note:** `Node 7.6.0` is required for async and await!\n\n## Usage\n\n```js\nconst unvault = require(\"unvault\");\n\nconst store = unvault();\n\nstore.insert(\"random\", 1000, () =\u003e Math.random());\n\nconst { value } = store.get(\"random\");\n```\n\n### TypeScript\n\n```js\nimport * as unvault from \"unvault\";\n\nconst store: Unvault = unvault();\n```\n\n### Manual\n\nPeriodic updates might not suit your application's needs. Unvault supports a manual mode that provides more control over which trackers receive an update and when. Trackers with an interval of `0` will only run once. Both automatic and manual trackers allow for an update trigger.\n\n```js\nstore.insert(\"random\", 0, () =\u003e Math.random());\n\nstore.trigger(\"random\");\n```\n\n### Advanced\n\nUnvault can be combined with a node servers like [Polka](https://github.com/lukeed/polka) or [Express](https://github.com/expressjs/express) to quickly deliver stored content to users. Trackers also work with `async` and `await` for asynchronous updates. Store your external fetch responses, database results and other in the vault for faster response times.\n\n```js\nconst polka = require(\"polka\");\nconst unvault = require(\"unvault\");\nconst fetch = require(\"node-fetch\");\n\nconst server = polka();\nserver.listen(3000);\n\nconst route = \"/api/fetch\";\nconst routes = unvault();\n\nroutes.insert(route, 2000, async () =\u003e {\n  const response = await fetch(\n    \"https://api.github.com/repos/vaneenige/unvault\"\n  );\n  return response.json();\n});\n\nserver.get(route, (req, res) =\u003e {\n  const { value } = routes.get(route);\n  server.send(res, 200, value, \"application/json\");\n});\n```\n\n## API\n\n### .insert(key, interval, update, options)\n\n_Inserts a tracker into the vault._\n\nReturns: Result of update function (use await for async updates).\n\n### .trigger(key)\n\n_Manually runs a tracker._\n\nReturns: Result of update function (use await for async updates).\n\n### .prototype\n\nAs `unvault` extends [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), all of its functions are available: `clear()`, `delete(key)`, `entries()` and more!\n\n\u003e **Note:** The update callback will receive the `key` as a parameter. Providing a `lifetime` variable (in ms) to the `options` object will delete the tracker and stop its automatic updates once it runs out.\n\n## Benchmarks\n\nFor this benchmark an example route is setup that searches a mongodb collection that contains 100 nodes. The node server is started with `node v9.0.0` and results are documented after a single warm-up run.\n\nThe benchmarking tool for results is the following:\n\n```sh\n$ wrk -t8 -c100 -d10s http://localhost:3000/:type/mongo\n```\n\n### Without unvault\n\n```\nThread Stats   Avg      Stdev     Max   +/- Stdev\n  Latency    44.23ms    8.44ms  80.36ms   65.70%\n  Req/Sec   271.83     26.52   353.00     64.25%\n21755 requests in 10.07s, 209.77MB read\n\nRequests/sec:   2160.05\nTransfer/sec:     20.83MB\n```\n\n### With unvault\n\n```\nThread Stats   Avg      Stdev     Max   +/- Stdev\n  Latency     4.89ms  391.21us   9.38ms   92.94%\n  Req/Sec     2.47k   341.17     9.22k    99.75%\n196758 requests in 10.10s, 1.85GB read\n\nRequests/sec:  19481.54\nTransfer/sec:    187.85MB\n```\n\n\u003e **Note:** Unvault aims to reduce the time spend creating a response. If the process normally takes a second to finish this solution will eliminate most of that second.\n\n## License\n\nMIT © [Colin van Eenige](https://use-the-platform.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaneenige%2Funvault","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaneenige%2Funvault","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaneenige%2Funvault/lists"}