{"id":43960468,"url":"https://github.com/codebycorey/express-key-value-store-ttl","last_synced_at":"2026-02-07T05:08:47.186Z","repository":{"id":238779687,"uuid":"797533677","full_name":"codebycorey/express-key-value-store-ttl","owner":"codebycorey","description":"Express based http service that is an in-memory key-value store that supports TTLs on the keys","archived":false,"fork":false,"pushed_at":"2024-05-14T01:47:36.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-29T12:49:36.252Z","etag":null,"topics":["expressjs","keyvaluestore","map","minheap"],"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/codebycorey.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-05-08T02:59:05.000Z","updated_at":"2024-05-14T01:47:39.000Z","dependencies_parsed_at":"2024-05-14T02:49:14.226Z","dependency_job_id":null,"html_url":"https://github.com/codebycorey/express-key-value-store-ttl","commit_stats":null,"previous_names":["codebycorey/express-key-value-store-ttl"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codebycorey/express-key-value-store-ttl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebycorey%2Fexpress-key-value-store-ttl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebycorey%2Fexpress-key-value-store-ttl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebycorey%2Fexpress-key-value-store-ttl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebycorey%2Fexpress-key-value-store-ttl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codebycorey","download_url":"https://codeload.github.com/codebycorey/express-key-value-store-ttl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebycorey%2Fexpress-key-value-store-ttl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29186754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T05:07:31.176Z","status":"ssl_error","status_checked_at":"2026-02-07T05:06:15.227Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["expressjs","keyvaluestore","map","minheap"],"created_at":"2026-02-07T05:08:46.511Z","updated_at":"2026-02-07T05:08:47.178Z","avatar_url":"https://github.com/codebycorey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# In-Memory Key-Value Store with TTL\n\nExpress based HTTP service that is an in-memory key-value store that supports TTLs on the keys\n\n## API Routes\nThis application provides a simple key-value store API with the following routes:\n\n### POST /set\nThis route sets a key to a value. It accepts a JSON body with the following properties:\n\n- `key` (string): The key to set.\n- `value` (string): The value to set the key to.\n- `ttlSeconds` (number, optional): The time-to-live (TTL) of the key in seconds. If provided, the key will automatically be removed after this duration.\nExample request:\n\n```\nPOST /set\nContent-Type: application/json\n\n{\n  \"key\": \"myKey\",\n  \"value\": \"myValue\",\n  \"ttlSeconds\": 3600\n}\n```\n\n\n## GET /get/:key\n\nThis route gets the value of a key. The key to get is specified as a URL parameter.\n\nExample request:\n\n```\nGET /get/myKey\n```\n\n## DELETE /delete/:key\n\nThis route deletes a key. The key to delete is specified as a URL parameter.\n\nExample request:\n\n```\nDELETE /delete/myKey\n```\n\n## DELETE /dropExpired\n\nThis route removes all keys that have expired.\n\nExample request:\n\n```\nDELETE /dropExpired\n```\n\nAll routes respond with a string message indicating the result of the operation.\n\n## Design decisions\n\nWhen designing my key value store, I wanted to make see lookup was efficient and I chose to store it using a `Map`. I also wanted to make sure we could efficiently remove any expired keys in the store. I went with a `MinHeap` to sort expirations.\n\n### Map for Key-Value Store\n\n- **Fast Access**: `Map` allows for O(1) time complexity for get, set, and delete operations \n\n### MinHeap for Expiration\n\nA MinHeap was used to keep track of key expirations. The key with the earliest expiration time sits at the root of the MinHeap. \n\n- **Efficient Minimum Lookup**: the minimum key-value with with the earliest expiration is always at the root of the heap. This allows for constant time O(1) lookup of the next key to expire.\n- **Efficient Removal**: When a key expires, it can be removed from the root of the MinHeap and the heap can be restructured in O(log n) time. This is more efficient than other data structures like arrays or linked lists, where removal can take O(n) time.\n- **Efficient Insertion**: Inserting a new key into the MinHeap takes O(log n) time\n\nThese design decisions provide a balance between efficient access (through the `Map`) and efficient expiration handling (through the `MinHeap`), making the system robust and performant.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebycorey%2Fexpress-key-value-store-ttl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodebycorey%2Fexpress-key-value-store-ttl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebycorey%2Fexpress-key-value-store-ttl/lists"}