{"id":15287973,"url":"https://github.com/ioki-mobility/node-ts-cache","last_synced_at":"2025-10-07T02:31:59.321Z","repository":{"id":60490392,"uuid":"542068487","full_name":"ioki-mobility/node-ts-cache","owner":"ioki-mobility","description":"Simple and extensible caching module supporting decorators","archived":false,"fork":true,"pushed_at":"2023-10-18T09:20:45.000Z","size":1488,"stargazers_count":2,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T12:46:14.556Z","etag":null,"topics":["cache","elasticsearch","filesystem","hacktoberfest","ioredis","memory","nodejs","postgresql"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@ioki/node-ts-cache","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"havsar/node-ts-cache","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ioki-mobility.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-27T12:17:59.000Z","updated_at":"2023-10-16T14:08:52.000Z","dependencies_parsed_at":"2023-02-08T09:31:47.148Z","dependency_job_id":null,"html_url":"https://github.com/ioki-mobility/node-ts-cache","commit_stats":null,"previous_names":["boredland/node-ts-cache"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2Fnode-ts-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2Fnode-ts-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2Fnode-ts-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2Fnode-ts-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ioki-mobility","download_url":"https://codeload.github.com/ioki-mobility/node-ts-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235412053,"owners_count":18986073,"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","elasticsearch","filesystem","hacktoberfest","ioredis","memory","nodejs","postgresql"],"created_at":"2024-09-30T15:43:37.655Z","updated_at":"2025-10-07T02:31:59.316Z","avatar_url":"https://github.com/ioki-mobility.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @ioki/node-ts-cache\n\n[![CI](https://github.com/ioki-mobility/node-ts-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/ioki-mobility/node-ts-cache/actions/workflows/ci.yml)\n[![The MIT License](https://img.shields.io/npm/l/node-ts-cache.svg)](http://opensource.org/licenses/MIT)\n[![Coverage Status](https://coveralls.io/repos/github/ioki-mobility/node-ts-cache/badge.svg?branch=main)](https://coveralls.io/github/ioki/node-ts-cache?branch=main)\n\nSimple and extensible caching module supporting decorators.\n\n## Install\n\n```bash\nyarn add @ioki/node-ts-cache\n```\n\n_Note: The underlying storage layer must be installed separately._\n\n## Storage\n\n| Storage                                                               | Install                                         |\n|-----------------------------------------------------------------------|-------------------------------------------------|\n| [memory](https://www.npmjs.com/package/@ioki/node-ts-cache-storage-memory)| ```yarn add @ioki/node-ts-cache-storage-memory```|\n| [node-fs](https://www.npmjs.com/package/@ioki/node-ts-cache-storage-node-fs)| ```yarn add @ioki/node-ts-cache-storage-node-fs```|\n| [ioredis](https://www.npmjs.com/package/@ioki/node-ts-cache-storage-ioredis)| ```yarn add @ioki/node-ts-cache-storage-ioredis```|\n| [postgres](https://www.npmjs.com/package/@ioki/node-ts-cache-storage-pg)| ```yarn add @ioki/node-ts-cache-storage-pg```|\n| [elasticsearch](https://www.npmjs.com/package/@ioki/node-ts-cache-storage-elasticsearch)| ```yarn add @ioki/node-ts-cache-storage-elasticsearch```|\n\n## Usage\n\n### Wrap your function calls `withCacheFactory`\n\nFunction wrapper factory for arbitrary functions. The cache key is caculated based on the parameters passed to the function.\n\n```ts\nimport { withCacheFactory, CacheContainer } from '@ioki/node-ts-cache'\nimport { MemoryStorage } from '@ioki/node-ts-cache-storage-memory'\n\nconst doThingsCache = new CacheContainer(new MemoryStorage())\n\nconst someFn = (input: { a: string, b: number })\n\nconst wrappedFn = withCacheFactory(doThingsCache)(someFn);\n\nconst result = someFn({ a: \"lala\", b: 123 })\n```\n\n### `@Cache` decorator\n\nCaches function response using the given options. By default, uses all arguments to build an unique key.\n\n_Note: @Cache will consider the return type of the function. If the return type is a thenable, it will stay that way, otherwise not._\n\n```ts\nimport { Cache, CacheContainer } from '@ioki/node-ts-cache'\nimport { MemoryStorage } from '@ioki/node-ts-cache-storage-memory'\n\nconst userCache = new CacheContainer(new MemoryStorage())\n\nclass MyService {\n    @Cache(userCache, {ttl: 60})\n    public async getUsers(): Promise\u003cstring[]\u003e {\n        return [\"Max\", \"User\"]\n    }\n}\n```\n\n### Using `getItem` and `setItem` directly\n\n```ts\nimport { CacheContainer } from '@ioki/node-ts-cache'\nimport { MemoryStorage } from '@ioki/node-ts-cache-storage-memory'\n\nconst myCache = new CacheContainer(new MemoryStorage())\n\nclass MyService {\n    public async getUsers(): Promise\u003cstring[]\u003e {\n        const { content: cachedUsers } = await myCache.getItem\u003cstring[]\u003e(\"users\")\n\n        if (cachedUsers) {\n            return cachedUsers\n        }\n\n        const newUsers = [\"Max\", \"User\"]\n\n        await myCache.setItem(\"users\", newUsers, {ttl: 60})\n\n        return newUsers\n    }\n}\n```\n\n## Logging\n\nThis project uses [debug](https://github.com/visionmedia/debug) to log useful caching information.\nSet environment variable **DEBUG=node-ts-cache** to enable logging.\n\n## Mocking\n\nJust use the memory storage adapter in your tests.\n\n## LICENSE\n\nDistributed under the MIT License. See LICENSE.md for more information.\n\n## Development \u0026 Testing\n\nThis project follows the monorepo architecture using yarn workspaces.\n\nTo start development and run tests for all the packages, run:\n\n```bash\ncd node-ts-cache\nyarn\nyarn build\nyarn test\n```\n\n## Release\n\nWe're using changeset to automate the release process. The only thing to be done is to [commit a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md#i-am-in-a-multi-package-repository-a-mono-repo).\n\n## Credits\n\nAs this is a fork of the original [node-ts-cache](https://github.com/havsar/node-ts-cache), all credit goes to the upstream project by [havsar](https://github.com/havsar).\n\nStructural changes have been made by [boredland](https://github.com/boredland) in order to align more with our use-case.\n\n## Contributing (complexity, asc)\n\n1. [join us @ioki](https://ioki.com/about-ioki/jobs/) and make this one of your projects\n2. create issues and pull requests, we're happy to enhance this\n\n## Contact\n\n\u003ca href=\"https://ioki.com/ioki-devs/\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/ioki-mobility/transitland-gql-client/blob/main/assets/ioki-light.png?raw=true\"\u003e\n    \u003cimg alt=\"ioki logo\" src=\"https://github.com/ioki-mobility/transitland-gql-client/blob/main/assets/ioki-dark.png?raw=true\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\nioki Mobility - [@ioki_mobility](https://twitter.com/ioki_mobility)\n\nProject Link: [https://github.com/ioki-mobility/node-ts-cache](https://github.com/ioki-mobility/node-ts-cache)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioki-mobility%2Fnode-ts-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fioki-mobility%2Fnode-ts-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioki-mobility%2Fnode-ts-cache/lists"}