{"id":14156609,"url":"https://github.com/notskamr/bun-sqlite-cache","last_synced_at":"2025-10-29T03:38:07.721Z","repository":{"id":216827417,"uuid":"742559904","full_name":"notskamr/bun-sqlite-cache","owner":"notskamr","description":"Source code for a Bun SQLite based key-value cache","archived":false,"fork":false,"pushed_at":"2024-06-17T08:29:49.000Z","size":34,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T22:03:32.536Z","etag":null,"topics":["bun","cache","kv-store","lru","sqlite","ttl"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/bun-sqlite-cache","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/notskamr.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-01-12T18:46:24.000Z","updated_at":"2024-11-28T10:41:33.000Z","dependencies_parsed_at":"2024-01-26T19:28:18.335Z","dependency_job_id":"aa995b6f-a01c-456f-a3af-e3a54b8e8840","html_url":"https://github.com/notskamr/bun-sqlite-cache","commit_stats":null,"previous_names":["notskamr/bun-sqlite-cache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notskamr%2Fbun-sqlite-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notskamr%2Fbun-sqlite-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notskamr%2Fbun-sqlite-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notskamr%2Fbun-sqlite-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notskamr","download_url":"https://codeload.github.com/notskamr/bun-sqlite-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238768422,"owners_count":19527197,"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":["bun","cache","kv-store","lru","sqlite","ttl"],"created_at":"2024-08-17T08:07:04.853Z","updated_at":"2025-10-08T01:04:49.105Z","avatar_url":"https://github.com/notskamr.png","language":"TypeScript","funding_links":[],"categories":["sqlite"],"sub_categories":[],"readme":"# Bun SQLite Cache\nBun SQLite cache is a Bun-ified version of [jkelin](https://github.com/jkelin)'s [sqlite-lru-cache](https://github.com/jkelin/cache-sqlite-lru-ttl) (with TTL). Bun's lightning-fast implementation makes this perfect for a quick in-memory caching solution with TTL support.\n\n## Installation\n```bash\nbun add bun-sqlite-cache\n```\n\n## Usage\nUsing this cache is dead simple: simply create a new BunSQLiteCache instance and you're set\n```typescript\nimport { BunSQLiteCache } from \"bun-sqlite-cache\";\n\nconst cache = new BunSQLiteCache();\n\ncache.set(\"foo\", { bar: \"baz\", waldo: [4, 3, 2, 8] });\nconst value = cache.get(\"foo\");\n\nconsole.log(value) // { bar: \"baz\", waldo: [4, 3, 2, 8] }\n```\n\n## Methods\n#### Initialize\n```typescript\nimport { BunSQLiteCache, BunSQLiteCacheConfiguration } from \"bun-sqlite-cache\";\n\n// the given values are the defaults\nconst options: BunSQLiteCacheConfiguration = {\n    database: \":memory:\", // database file or in memory: default :- in memory sqlite table\n    defaultTtlMs: undefined, // the default time it takes (in ms) for a cached row to expire: default :- no expiry\n    maxItems: undefined, // max number of items allowed in cache. if number of items is exceeded then LRU eviction policy is used: default :- no limit\n    compress: false // whether to compress data before putting it in the cache (uses Bun's synchronous gzip)\n}\n\nconst cache = new BunSQLiteCache(options)\n```\n#### `set(key: string, value: any, opts?: { ttlMs?: number, compress?: boolean }): boolean`\nAdds a value to the cache by serializing the given value and adding it to the table\n- `key`: the key to store the value under\n- `value`: the value to store - can be anything serializable by 'v8'\n- opts:\n    - `ttlMs`: the time it takes (in ms) for a cached row to expire: default:- no expiry\n    - `compress`: whether to compress data before putting it in the cache (uses Bun's synchronous gzip)\n- returns: `boolean` dictating whether the value was successfully added to the cache\n\n#### `get(key: string, withMeta?: boolean):  any | ValueWithMeta\u003cT\u003e | undefined`\nGets a value from the cache by deserializing the value stored under the given key\n- `key`: the key to get the value from\n- `withMeta`: whether to return the value with its metadata (i.e. `compressed` and `key`): default:- false\n  - if `withMeta` is `true`, the return value will be of type `ValueWithMeta\u003cT\u003e`: `{ value: any, compressed: boolean, key: string }`\n- returns: Deserialized value stored under the given key (`any`)\n\n#### `delete(key: string): void`\nDeletes a value from the cache\n- `key`: the key to delete the value from\n- returns: void\n\n#### `clear(): void`\nClears the cache\n- returns: void\n\n## Contributing\nContributions are welcome - this is my first package so it's probably riddled with stuff that could be improved.\nFeel free to open an issue or submit a pull request.\n\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotskamr%2Fbun-sqlite-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotskamr%2Fbun-sqlite-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotskamr%2Fbun-sqlite-cache/lists"}