{"id":15021668,"url":"https://github.com/devvali/cache-keeper","last_synced_at":"2026-01-26T17:04:01.912Z","repository":{"id":252573920,"uuid":"840840104","full_name":"DevVali/cache-keeper","owner":"DevVali","description":"A simple and lightweight caching solution for your Discord bot.","archived":false,"fork":false,"pushed_at":"2024-08-12T11:20:41.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T05:25:07.768Z","etag":null,"topics":["cache","cache-storage","caching","discord-bot","discord-js"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cache-keeper","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/DevVali.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-10T21:07:04.000Z","updated_at":"2024-09-08T15:22:48.000Z","dependencies_parsed_at":"2024-08-10T21:30:32.480Z","dependency_job_id":"f087160a-4ae3-4e23-a9a7-75e7d6130530","html_url":"https://github.com/DevVali/cache-keeper","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"b82c6844d5c440b665b16c4dc7620eff765a1a09"},"previous_names":["devvali/cache-keeper"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevVali%2Fcache-keeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevVali%2Fcache-keeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevVali%2Fcache-keeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevVali%2Fcache-keeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevVali","download_url":"https://codeload.github.com/DevVali/cache-keeper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238909258,"owners_count":19550836,"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","cache-storage","caching","discord-bot","discord-js"],"created_at":"2024-09-24T19:56:53.069Z","updated_at":"2025-10-29T22:31:10.407Z","avatar_url":"https://github.com/DevVali.png","language":"TypeScript","readme":"[![GitHub release](https://img.shields.io/github/release/DevVali/cache-keeper.svg)](https://github.com/DevVali/cache-keeper/releases/latest)\n[![npm](https://img.shields.io/npm/dt/cache-keeper.svg)](https://www.npmjs.com/package/cache-keeper)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/DevVali/cache-keeper?tab=MIT-1-ov-file#readme)\n\n# Cache Keeper\n\nA simple and lightweight caching solution for your Discord bot.\n\n## Installation\n\nTo get started, install the library using npm (or your other favorite package manager):\n\n```bash\nnpm install cache-keeper\n```\n\n## Usage\n\n\u003e \u003cimg align=\"top\" src=\"https://upload.wikimedia.org/wikipedia/en/3/35/Information_icon.svg\" alt=\"image\" width=\"25\" height=\"auto\"\u003e The term TTL refers to Time to Live.\n\n### Creating a cache instance\n\n```js\n// Create a cache instance with a default TTL of 10 minutes\nconst cache = new Keeper();\n\n// Create a cache instance with a custom default TTL of 30 minutes\nconst longCache = new Keeper(1800000);\n```\n\n### Setting values\n\n-   Use the `set` method to store a key-value pair in the cache\n-   You can optionally specify a custom TTL for an entry that overrides the default\n\n```js\ncache.set('userId', '12345');\n\n// Set with a custom TTL of 5 minutes\ncache.set('username', 'AwesomeUser', 300000);\n```\n\n### Retrieving values\n\n-   Use the `get` method to retrieve a value from the cache\n-   You can optionally specify a default value to return if the entry is not set\n\n```js\nconsole.log(cache.get('userId')); // '12345'\nconsole.log(cache.get('userNickname', 'DefaultNick')); // 'DefaultNick'\n```\n\n### Other useful methods\n\n-   `has`: Checks if a key is cached\n-   `delete`: Removes an entry from the cache\n-   `clear`: Removes all entries from the cache\n-   `size`: Returns the current number of entries in the cache\n\n### Advanced usage\n\n-   `getExpirationTime`: Returns the expiration time of an entry\n-   `clearExpired`: Removes all expired entries from the cache\n\n### TypeScript support\n\n`cache-keeper` provides robust TypeScript support for type safety and code maintainability.\n\n```ts\n// Define a type for the cache key\ntype UserId = string;\n\n// Define an interface for the cache value\ninterface UserData {\n    username: string;\n    userNickname: string;\n    createdTimestamp: number;\n}\n\n// Create a cache instance using generic types for key and value types\nconst userCache = new Keeper\u003cUserId, UserData\u003e();\n\n// Store user data in the cache\nuserCache.set('12345', {\n    username: 'AwesomeUser',\n    userNickname: 'DefaultNick',\n    createdTimestamp: 1723320168561,\n});\n\n// Retrieve user data from the cache\nif (userCache.has('12345')) {\n    const userData = userCache.get('12345')!;\n    console.log(userData.username); // TypeScript knows the shape of userData\n}\n```\n\n## Resources\n\n-   [`@discordjs/collection`](https://www.npmjs.com/package/@discordjs/collection) (Dependency)\n-   [Repo template](https://github.com/bit-js/library)\n-   [Discord bot template](https://github.com/devvali/djs-template)\n\n## Issues\n\nIf you encounter any issues or have suggestions, please [open an issue](https://github.com/DevVali/cache-keeper/issues).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevvali%2Fcache-keeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevvali%2Fcache-keeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevvali%2Fcache-keeper/lists"}