{"id":18848355,"url":"https://github.com/pmbanugo/midas-cache","last_synced_at":"2026-01-23T16:36:56.484Z","repository":{"id":252780858,"uuid":"841305058","full_name":"pmbanugo/midas-cache","owner":"pmbanugo","description":"midas-cache is a caching middleware that can boost your apps by 70% - 95%","archived":false,"fork":false,"pushed_at":"2024-08-13T09:33:37.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-17T12:39:10.349Z","etag":null,"topics":["cache","cache-middleware"],"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/pmbanugo.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-08-12T06:22:29.000Z","updated_at":"2024-08-30T02:11:24.000Z","dependencies_parsed_at":"2024-11-08T03:12:27.456Z","dependency_job_id":"a3e7396a-780d-4ba9-9afd-b397729fa6d8","html_url":"https://github.com/pmbanugo/midas-cache","commit_stats":null,"previous_names":["pmbanugo/midas-cache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pmbanugo/midas-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmbanugo%2Fmidas-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmbanugo%2Fmidas-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmbanugo%2Fmidas-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmbanugo%2Fmidas-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmbanugo","download_url":"https://codeload.github.com/pmbanugo/midas-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmbanugo%2Fmidas-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28695600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T15:57:05.722Z","status":"ssl_error","status_checked_at":"2026-01-23T15:56:27.656Z","response_time":59,"last_error":"SSL_read: 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":["cache","cache-middleware"],"created_at":"2024-11-08T03:12:18.596Z","updated_at":"2026-01-23T16:36:56.465Z","avatar_url":"https://github.com/pmbanugo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# midas-cache: turbo-charge your web apps \u0026 APIs\n\n**midas-cache** is a caching middleware that can boost your apps by 70% - 95%. It reduces the response time and increases the number of requests your server can handle. It's intended for use on the server, for server-side rendered apps (e.g. blogs) and regular REST API.\n\nIt currently only works with Bun but might work with Deno since it uses the web platform [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request)/[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) API. Support for Node.js web servers will be implemented _soon_.\n\n## Installation\n\n_midas-cache_ is currently only available on [JSR](https://jsr.io/@pmbanugo/midas-cache). You can install the package using npm:\n\n```sh\nnpx jsr add @pmbanugo/midas-cache\n```\n\nOr any of the following for other package managers:\n\n```sh\nbunx jsr add @pmbanugo/midas-cache\npnpm dlx jsr add @pmbanugo/midas-cache\nyarn dlx jsr add @pmbanugo/midas-cache\n```\n\n## Usage\n\nTo use `midas-cache`, you need to integrate it into your server setup. Below is an example of how to use it with a _Bun_ server:\n\n```typescript\nimport { createCacheMiddleware } from \"@pmbanugo/midas-cache\";\n\nconst cacheOptions = {\n  maxAge: 3600, // 1 hour\n  staleWhileRevalidate: 300, // 5 minutes\n  cacheableStatusCodes: [200, 301, 302],\n};\n\n// Create the cache middleware\nconst cacheMiddleware = createCacheMiddleware(cacheOptions);\n\n// Create a simple Bun server\nconst server = Bun.serve({\n  port: 3000,\n  async fetch(req: Request) {\n    // Use the cache middleware\n    return cacheMiddleware(req, async (request: Request) =\u003e {\n      // Simulate some processing time\n      await new Promise((resolve) =\u003e setTimeout(resolve, 100));\n\n      // Return a simple response\n      return new Response(`Hello, World! Timestamp: ${Date.now()}`, {\n        headers: {\n          \"Content-Type\": \"text/plain\",\n          \"Cache-Control\": \"max-age=60\", // Cache for 1 minute\n        },\n      });\n    });\n  },\n});\n\nconsole.log(`Server running at http://localhost:${server.port}`);\n```\n\nCreating the middleware requires a few optional properties. The example above specified tells the middleware to cache requests with the specified value. They'll stay fresh for 1 hour, and it can serve stale response for up to 5 minutes.\n\nHere's an example of how to use it with Elysia framework:\n\n```typescript\nconst cacheMiddleware = createCacheMiddleware(cacheOptions);\nconst app = new Elysia()\n  .get(\"/\", () =\u003e \"Hello, welcome to my app! ❤︎ midas-cache\")\n  .get(\"/records\", async () =\u003e {\n    const results = await db.execute(\"SELECT * FROM expenses\");\n    return results.rows;\n  });\n\nconst handle = (request: Request) =\u003e app.handle(request);\n\nconst server = Bun.serve({\n  port: port,\n  async fetch(req: Request) {\n    // Use the cache middleware\n    return cacheMiddleware(req, handle);\n  },\n});\n```\n\n### Example with benchmark\n\nYou can find a working example at [pmbanugo/midas-cache-examples](https://github.com/pmbanugo/midas-cache-examples). It's a REST API that stores data using SQLite and Turso. It runs four web servers as described below.\n\n1. `localhost:3000`: Makes use of Turso's embedded replica where by there's a local SQLite DB that it reads from, and occasionally syncs with the remote Turso database.\n2. `localhost:3001`: Call's the Turso database directly, with requests going over the internet. The primary database is hosted in Frankfurt, which is the datacenter closest server to me.\n3. `localhost:3003`: Makes use of Turso's embedded replica and `midas-cache` to cache and serve cached response.\n4. `localhost:3004`: Makes use of `midas-cache` but calls the remote Turso database when it needs to refresh or get fresh data.\n\nThe following data is the result of the benchmark.\n\n![Screenshot of the benchmark measurement](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwsewy0emea1tpszbr72.png)\n\nUsing local SQLite + remote Turso DB\n\n```sh\n$ oha --no-tui -n 500  http://localhost:3000/records\n\nSummary:\n  Success rate:\t100.00%\n  Total:\t0.0660 secs\n  Slowest:\t0.0180 secs\n  Fastest:\t0.0015 secs\n  Average:\t0.0063 secs\n  Requests/sec:\t7580.3614\n```\n\nUsing only remote Turso DB\n\n```sh\n$ oha --no-tui -n 500  http://localhost:3001/records\n\nSummary:\n  Success rate:\t100.00%\n  Total:\t0.7538 secs\n  Slowest:\t0.3827 secs\n  Fastest:\t0.0195 secs\n  Average:\t0.0733 secs\n  Requests/sec:\t663.3302\n```\n\nUsing the cache middleware and remote Turso DB. The slowest call is the call to the remote DB.\n\n```sh\n$ oha --no-tui -n 500  http://localhost:3004/records\n\nSummary:\n  Success rate:\t100.00%\n  Total:\t0.2626 secs\n  Slowest:\t0.2611 secs\n  Fastest:\t0.0001 secs\n  Average:\t0.0249 secs\n  Requests/sec:\t1903.7218\n```\n\nUsing the cache middleware, local SQLite (embedded replica), and remote Turso DB for synchronisation.\n\n```sh\n$ oha --no-tui -n 500  http://localhost:3003/records\n\nSummary:\n  Success rate:\t100.00%\n  Total:\t0.0186 secs\n  Slowest:\t0.0087 secs\n  Fastest:\t0.0006 secs\n  Average:\t0.0017 secs\n  Requests/sec:\t26916.3311\n```\n\n\u003e Regardless of the figures you see on this benchmark, you should benchmark it with your actual application.\n\n## Configuration Options\n\nThe `createCacheMiddleware` function accepts an options object with the following properties:\n\n- `storagePath` (string): Path to the storage for caching.\n- `maxAge` (number, optional): Maximum age for cache entries to stay fresh (in seconds). Default is 3600 (1 hour).\n- `staleWhileRevalidate` (number, optional): Time to serve stale content while revalidating in seconds. Default is 60 (1 minute).\n- `cacheableStatusCodes` (number[], optional): List of status codes that are cacheable. Default is [200, 301, 302].\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmbanugo%2Fmidas-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmbanugo%2Fmidas-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmbanugo%2Fmidas-cache/lists"}