{"id":21681851,"url":"https://github.com/alvarocastro/volatile-map","last_synced_at":"2025-10-09T21:14:24.127Z","repository":{"id":38106388,"uuid":"337902236","full_name":"alvarocastro/volatile-map","owner":"alvarocastro","description":"ES6 Map object whose values are deleted after a TTL","archived":false,"fork":false,"pushed_at":"2023-04-05T09:58:23.000Z","size":665,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T06:43:56.783Z","etag":null,"topics":["cache","map","map-cache","storage","volatile"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/volatile-map","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/alvarocastro.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-11T01:34:27.000Z","updated_at":"2023-02-28T07:26:33.000Z","dependencies_parsed_at":"2024-11-25T15:44:43.441Z","dependency_job_id":null,"html_url":"https://github.com/alvarocastro/volatile-map","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":0.3870967741935484,"last_synced_commit":"5fea815ad730090b3a30adf4ab4189b8355b03e5"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarocastro%2Fvolatile-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarocastro%2Fvolatile-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarocastro%2Fvolatile-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarocastro%2Fvolatile-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alvarocastro","download_url":"https://codeload.github.com/alvarocastro/volatile-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248530606,"owners_count":21119592,"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","map","map-cache","storage","volatile"],"created_at":"2024-11-25T15:32:00.153Z","updated_at":"2025-10-09T21:14:19.084Z","avatar_url":"https://github.com/alvarocastro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VolatileMap\n\n[![NPM](https://img.shields.io/npm/v/volatile-map)](https://www.npmjs.com/package/volatile-map)\n[![Build status](https://img.shields.io/github/workflow/status/alvarocastro/volatile-map/build)](https://github.com/alvarocastro/volatile-map/actions?query=workflow%3Abuild)\n[![Maintainability status](https://img.shields.io/codeclimate/maintainability/alvarocastro/volatile-map)](https://codeclimate.com/github/alvarocastro/volatile-map/maintainability)\n[![Coverage status](https://img.shields.io/coveralls/github/alvarocastro/volatile-map)](https://coveralls.io/github/alvarocastro/volatile-map?branch=master)\n[![Bundle size](https://img.shields.io/bundlephobia/min/volatile-map)](https://bundlephobia.com/result?p=volatile-map)\n[![Code style: XO](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)\n[![Release: Semantic](https://img.shields.io/badge/%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nMinimalist and performant `Map` object that is fully compatible with the [ES6 `Map` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) (it extends from it) whose values are deleted after a TTL of being set, like a cache.\n\n- [Install](#install)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Support](#support)\n\n## Install\n\n```bash\nnpm install volatile-map\n```\n\n## Usage\n\n```js\nimport VolatileMap from 'volatile-map';\n\nconst cache = new VolatileMap(3000); // Values expire after 3 seconds\n\ncache.set('foo', 'bar');\ncache.set('baz', 'qux', 5000);\nconsole.log(cache.get('foo'));\n// =\u003e 'bar'\nconsole.log(cache.get('baz'));\n// =\u003e 'qux'\n\nsetTimeout(function () {\n\tconsole.log(cache.get('foo'));\n\t// =\u003e undefined\n\tconsole.log(cache.get('baz'));\n\t// =\u003e 'qux'\n}, 4000);\n```\n\n### VolatileMap([ttl = 600000])\n\nConstructor.\n\n#### ttl\n\nType: `Number`\n\nTime to live of the values and keys of the map, after that time, keys and values are deleted.\n\n#### VolatileMap.set(key, value[, ttl])\n\nThis method behaves the same as the [ES6 `Map.set()` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set), but adds an extra optional argument `ttl` that allows to set a specific time to live to each key. By default uses the `ttl` supplied when constructing the object.\n\n#### Other methods\n\nSee the [ES6 `Map` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) documentation to see all the methods.\n\n## Contributing\n\nContributions are always welcome! Please run `npm test` beforehand to ensure everything is ok.\n\n## Support\n\nIf you use this package please consider starring it :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvarocastro%2Fvolatile-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falvarocastro%2Fvolatile-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvarocastro%2Fvolatile-map/lists"}