{"id":25193775,"url":"https://github.com/dominictobias/keshi","last_synced_at":"2025-04-04T14:04:16.604Z","repository":{"id":49672469,"uuid":"164871658","full_name":"dominictobias/keshi","owner":"dominictobias","description":"An in-memory cache for Node and the browser designed for Promises","archived":false,"fork":false,"pushed_at":"2025-01-16T14:04:42.000Z","size":230,"stargazers_count":76,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T13:06:02.851Z","etag":null,"topics":["async","cache","in-memory","javascript","nodejs","store"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/dominictobias.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-01-09T13:50:22.000Z","updated_at":"2025-01-24T03:50:14.000Z","dependencies_parsed_at":"2025-01-25T14:33:11.542Z","dependency_job_id":"e5ebd38e-9a8d-40a5-82f4-2997525a1d06","html_url":"https://github.com/dominictobias/keshi","commit_stats":null,"previous_names":["sekoyo/keshi","dominictobias/keshi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Fkeshi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Fkeshi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Fkeshi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictobias%2Fkeshi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominictobias","download_url":"https://codeload.github.com/dominictobias/keshi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247188107,"owners_count":20898445,"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":["async","cache","in-memory","javascript","nodejs","store"],"created_at":"2025-02-09T23:11:48.466Z","updated_at":"2025-04-04T14:04:16.588Z","avatar_url":"https://github.com/dominictobias.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keshi\n\n[![Keshi on NPM](https://img.shields.io/npm/v/keshi.svg)](https://www.npmjs.com/package/keshi)\n[![CI](https://github.com/sekoyo/keshi/actions/workflows/ci.yml/badge.svg)](https://github.com/sekoyo/keshi/actions/workflows/ci.yml)\n\nKeshi is a tiny in-memory cache for Node and the browser that is especially suited to storing Promises (e.g. caching fetch requests).\n\n```js\nimport Keshi from 'keshi'\n// or\nconst Keshi = require('keshi')\n```\n\n\u003ch2\u003eUsage\u003c/h2\u003e\n\n```js\nconst cache = new Keshi()\n\nconst user = await cache.resolve(\n  'user',\n  () =\u003e fetch('https://myapi.com/user').then(r =\u003e r.json()),\n  '5mins'\n)\n```\n\nWhat this will do:\n\n- Fetch the user from the API as it doesn't have it in cache.\n- If called again within 5 minutes it will return the cached user.\n- If called after 5 minutes it will fetch the user again and re-cache.\n\nKeshi automatically cleans up expired items.\n\n\u003ch2\u003eAPI\u003c/h2\u003e\n\n#### `cache.resolve\u003cT\u003e(key: string, getValue: () =\u003e T | Promise\u003cT\u003e, expiresIn?: number | string) =\u003e Promise\u003cT\u003e`\n\n```ts\nfunction getCachedUser() {\n  return cache.resolve(\n    'user',\n    () =\u003e fetch('https://myapi.com/user').then(r =\u003e r.json()),\n    '5mins' // Anything 'ms' package accepts or milliseconds as a number. Omit for no expiry.\n  )\n}\n\nconst user1 = await getCachedUser() // First time caches the promise and returns it\nconst user2 = await getCachedUser() // Second time returns the first promise if within 5mins\n```\n\nYou can use plain values but they must still be awaited:\n\n```ts\nconst plainValue = await cache.resolve('mynumber', () =\u003e 5, '10mins')\nconsole.log(plainValue) // prints 5\n```\n\n#### `cache.delete(key: string, matchStart?: boolean)`\n\nExplicitly delete a cached object.\n\nNote: expired objects are automatically cleanup up.\n\nIf `true` is passed for `matchStart` then any cache _starting_ with the `key` will be deleted:\n\n```js\ncache.del(`project.${projectId}.`, true) // Delete all caches under this projectId\n```\n\n#### `cache.clear()`\n\nClear the whole cache.\n\n#### `cache.teardown()`\n\nA stale cache cleanup interval is running in the background. If your cache doesn't last the lifetime of your application then you should call teardown.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictobias%2Fkeshi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominictobias%2Fkeshi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictobias%2Fkeshi/lists"}