{"id":15899143,"url":"https://github.com/prozi/latermom","last_synced_at":"2025-03-20T17:30:43.263Z","repository":{"id":35126561,"uuid":"210033182","full_name":"Prozi/latermom","owner":"Prozi","description":"simple, zero-dependency, in-memory, lazy cache for javascript","archived":false,"fork":false,"pushed_at":"2024-05-22T23:08:56.000Z","size":689,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-23T00:24:37.573Z","etag":null,"topics":["browser","cache","es6-javascript","lazy","nodejs","universal"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Prozi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-09-21T18:16:56.000Z","updated_at":"2024-05-23T00:24:41.067Z","dependencies_parsed_at":"2024-05-23T00:24:39.230Z","dependency_job_id":"33e0903e-db75-4cda-b511-e35e137be38b","html_url":"https://github.com/Prozi/latermom","commit_stats":{"total_commits":20,"total_committers":5,"mean_commits":4.0,"dds":0.65,"last_synced_commit":"4af6efa455ca2cf21ac43d3364e74f182a7cb039"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prozi%2Flatermom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prozi%2Flatermom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prozi%2Flatermom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prozi%2Flatermom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Prozi","download_url":"https://codeload.github.com/Prozi/latermom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244660144,"owners_count":20489296,"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":["browser","cache","es6-javascript","lazy","nodejs","universal"],"created_at":"2024-10-06T10:11:14.977Z","updated_at":"2025-03-20T17:30:42.962Z","avatar_url":"https://github.com/Prozi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\nLater Mom?\n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[\u003cimg src=\"https://img.shields.io/npm/v/@pietal.dev/cache?style=for-the-badge\u0026color=success\" alt=\"npm version\" /\u003e](https://www.npmjs.com/package/@pietal.dev/cache?activeTab=versions)\n\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\nYou know when you were a kid and mom told you to clean your room,\u003cbr/\u003e\nwhen you was busy with something else, your answer would always be the same: 'later, mom'.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nThis library is the universal 0 dependencies lazy cache implementation,\u003cbr/\u003e\nleveraging usage of es6 data structures.\n\u003c/p\u003e\n\n## Installation\n\n`yarn add @pietal.dev/cache --save`\n\n## Usage\n\n```javascript\nconst { Cache } = require(\"@pietal.dev/cache\")\n\nconst maxSize = 2 // will limit max cache size upon cache.get()\nconst getUser = async (id) =\u003e {\n  const response = await fetch(\"https://dummyjson.com/users/\" + id)\n  const { firstName, lastName, address } = await response.json()\n\n  return {\n    id,\n    name: `${firstName} ${lastName}`,\n    address,\n  }\n}\n\nconst usersCached = new Cache(getUser, maxSize)\n\nPromise.all([\n  usersCached.get(1),\n  usersCached.get(2),\n  usersCached.get(3),\n  usersCached.get(4),\n]).then((users) =\u003e {\n  console.log(usersCached.data) // contains only last maxSize users (3 and 4)\n  console.log(usersCached.size) // 2\n})\n```\n\n```javascript\nconst { Cache } = require(\"@pietal.dev/cache\")\n// create cache with factory function (may take any number of parameters)\nconst cache = new Cache(() =\u003e Math.random())\n\n// each time you call the cache.get with same parameters\n// you will get the same once lazy cached answer\nconst a = cache.get(1, 2, 3)\nconst b = cache.get(1, 2, 3) // this will return the same as above\nconst c = cache.get(1, 2)\nconst d = cache.get(1, 2, 4)\n\nconsole.log(a === b) // true\nconsole.log(a !== c) // true\nconsole.log(a !== d) // true\n```\n\n## API\n\n```typescript\nclass Cache\u003cT = unknown\u003e {\n  constructor(factoryFunction: (...args: any[]) =\u003e T, maxSize: number = Infinity) {\n    //\n  }\n}\n```\n\n- creates a LaterMom (Lazy Map) instance with factory function for lazy cache\n\nmethods\n\n- `get(...args: any[]): T` - get entry at key created from args, lazy instantiated by factory\n- `createKey(...args: any[]): string` - creates string key\n- `create(...args: any[]): T` - wrapped factory function\n- `hasKey(key: string): boolean` - check if has entry at key\n- `has(...args: any[]): boolean` - check if has entry at key created from args\n- `deleteKey(key: string): boolean` - deletes entry from data at key\n- `delete(...args): boolean` - deletes entry from data at key created from args\n- `size: number` - returns size of data\n- `maxSize: number` - on insert the oldest items are deleted until reached maxSize\n\nproperties:\n\n- data: Map\n\n## Tests\n\n```bash\n$ jest\n PASS  ./index.test.js\n  ✓ Calls factory once when asked for same key many times (62 ms)\n  ✓ Getter is able to handle multiple arguments\n  ✓ Readme has working code (1 ms)\n\nTest Suites: 1 passed, 1 total\nTests:       3 passed, 3 total\nSnapshots:   0 total\nTime:        0.946 s, estimated 1 s\nRan all test suites.\nDone in 1.44s.\n```\n\n## License\n\nMIT\n\n## Author\n\nJacek Pietal @ 2019-2021\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprozi%2Flatermom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprozi%2Flatermom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprozi%2Flatermom/lists"}