{"id":16831106,"url":"https://github.com/nonameprovided/dscache","last_synced_at":"2025-03-17T22:50:31.620Z","repository":{"id":98742406,"uuid":"363602533","full_name":"NoNameProvided/dscache","owner":"NoNameProvided","description":"Dead simple LRU style in-memory key-value cache with eager key eviction.","archived":false,"fork":false,"pushed_at":"2021-05-02T22:03:40.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T04:42:46.761Z","etag":null,"topics":["lru","lru-cache"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/NoNameProvided.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-05-02T08:29:29.000Z","updated_at":"2025-02-25T16:59:41.000Z","dependencies_parsed_at":"2023-03-13T15:55:09.493Z","dependency_job_id":null,"html_url":"https://github.com/NoNameProvided/dscache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Fdscache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Fdscache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Fdscache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Fdscache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NoNameProvided","download_url":"https://codeload.github.com/NoNameProvided/dscache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244122467,"owners_count":20401430,"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":["lru","lru-cache"],"created_at":"2024-10-13T11:42:17.310Z","updated_at":"2025-03-17T22:50:31.600Z","avatar_url":"https://github.com/NoNameProvided.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DSCache\n\n[![CI](https://github.com/NoNameProvided/dscache/actions/workflows/continuous-integration-workflow.yml/badge.svg)](https://github.com/NoNameProvided/dscache/actions/workflows/continuous-integration-workflow.yml)\n![npm](https://img.shields.io/npm/v/dscache)\n[![Dependency Status](https://david-dm.org/NoNameProvided/dscache.svg)](https://david-dm.org/typestack/typedi)\n\nA dead-simple LRU style in-memory key-value cache with **eager key eviction**.\n\n### Key features\n\n- fast, light-weight \u0026 zero-dependency\n- eager key eviction policy\n- always up-to-date Typescript typings\n- modern, written in ES2020 (Node LTS 14+)\n- uses native ES modules ([docs](https://nodejs.org/api/esm.html))\n- handy helper function to estimate cache size in memory\n\n## Install\n\n```bash\nnpm install dscache\n```\n\n## Usage\n\n```ts\nimport { DSCache } from 'dscache';\n\nconst lruCache = new DSCache({ size: 1000 });\n\nlruCache.set('user-token:231', userTokenObject, { ttl: 30_000 });\nlruCache.get('user-token:231');\n// -\u003e returns userTokenObject\n```\n\n## API\n\n#### Creating a cache instance\n\n```ts\nconst cacheInstance = new DSCache({ size: 10000 });\n```\n\n#### Checking current size of the cache\n\n```ts\ncacheInstance.size;\n```\n\nThe `size` property returns the count of currently stored items in the cache.\n\n#### Setting a value\n\n```ts\ncacheInstance.set(key: string; value: any; options?: { ttl?: number }): void;\n```\n\nSetting values can be done via the `set()` methods. The key must be a string\nand value can be anything. Optionally a time to live (`ttl`) option can be\nspecified in milliseconds. When TTL is set the item will be auto-removed from\nthe cache after the specified duration.\n\n#### Getting a value\n\nThere are two ways to get a value from the cache: `get()` and `peak()` methods.\n\n```ts\ncacheInstance.get(key: string): T | undefined;\n```\n\nThe `get()` method returns the value saved under the specified key or undefined\nif the key doesn't exist. This method also marks the item as recently used\npreventing it from being removed.\n\n```ts\ncacheInstance.peak(key: string): T | undefined;\n```\n\nThe `peak()` method also returns the value saved under the specified key or\nundefined if the key doesn't exist. However, using this method won't mark the\nitem as recently used.\n\n#### Checking if a value is cached\n\n```ts\ncacheInstance.has(key: string): boolean;\n```\n\nThe `has()` function returns `true` if the specified key exists in the cache or\n`false` otherwise.\n\n#### Deleting a value\n\n```ts\ncacheInstance.delete(key: string): void;\n```\n\nThe `delete()` function removes the specified key from the cache.\n\n#### Resting the cache\n\n```ts\ncacheInstance.reset(): void;\n```\n\nThe `reset()` function removes all cached items from the cache.\n\n## License\n\n[MIT License](./LICENSE) © Attila Oláh\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonameprovided%2Fdscache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnonameprovided%2Fdscache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonameprovided%2Fdscache/lists"}