{"id":13718791,"url":"https://github.com/oslabs-beta/zoic","last_synced_at":"2026-02-24T21:32:01.829Z","repository":{"id":37026482,"uuid":"502072044","full_name":"oslabs-beta/zoic","owner":"oslabs-beta","description":"A REST API-caching middleware library for Oak/Deno","archived":false,"fork":false,"pushed_at":"2025-01-23T23:08:17.000Z","size":835,"stargazers_count":72,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-23T04:41:56.792Z","etag":null,"topics":["api","cache","cache-control","cache-storage","caching","deno","devtools","http","javascript","middleware","oak","redis","rest","restful-api","server","storage","typescript"],"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/oslabs-beta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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},"funding":{"github":"open-source-labs","custom":["https://donorbox.org/donations-to-oslabs-inc"]}},"created_at":"2022-06-10T14:24:42.000Z","updated_at":"2025-08-27T12:31:07.000Z","dependencies_parsed_at":"2025-03-30T11:31:06.709Z","dependency_job_id":"80eaf261-6d4a-43bd-8a4c-ee7532bcf6a8","html_url":"https://github.com/oslabs-beta/zoic","commit_stats":{"total_commits":176,"total_committers":8,"mean_commits":22.0,"dds":0.2102272727272727,"last_synced_commit":"b96f3d4279ef6af73950d1a47e95ef3e90178178"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/oslabs-beta/zoic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oslabs-beta%2Fzoic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oslabs-beta%2Fzoic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oslabs-beta%2Fzoic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oslabs-beta%2Fzoic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oslabs-beta","download_url":"https://codeload.github.com/oslabs-beta/zoic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oslabs-beta%2Fzoic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29801021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T21:02:39.706Z","status":"ssl_error","status_checked_at":"2026-02-24T21:02:21.834Z","response_time":75,"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":["api","cache","cache-control","cache-storage","caching","deno","devtools","http","javascript","middleware","oak","redis","rest","restful-api","server","storage","typescript"],"created_at":"2024-08-03T01:00:37.815Z","updated_at":"2026-02-24T21:32:01.803Z","avatar_url":"https://github.com/oslabs-beta.png","language":"TypeScript","funding_links":["https://github.com/sponsors/open-source-labs","https://donorbox.org/donations-to-oslabs-inc"],"categories":[],"sub_categories":[],"readme":"\u003chr\u003e\n  \u003cbr\u003e\n    \u003ch3 align=\"center\"\u003eCaching middleware library for Oak\u003c/h3\u003e\n  \u003cbr\u003e\n\u003chr\u003e\n\n## Table of Contents\n\n1. [Description](#description)\n2. [Getting Started](#get-started)\n3. [Middleware and caching](#middleware)\n4. [Authors](#authors)\n5. [License](#license)\n\n## \u003ca name=\"description\"\u003e\u003c/a\u003eDescription\n\nZoic is an easy-to-use middleware library for caching responses from RESTful API endpoints in Oak, built for the Deno JavaScript runtime. Zoic provides both LRU and LFU in-memory caches, as well as support for Redis caches. Developers can use Zoic to easily cache HTTP responses with one simple middleware function that automatically handles both caching response data in the event of a cache miss, and sending responses on cache hits.\n\n### Zoic Developer Tool\n\nThe Zoic Developer Tool allows developers to monitor cache metrics in real time. The easiest to get it is to [add it from the Chrome Web Store.](https://chrome.google.com/webstore/detail/zoic-dev-tools/cnoohkfilnjedjeamhmpokfgaadgkgcl)\nCheckout the [Zoic Developer Tool README](./zoic_dev_tool/README.md/) for more details.\n\n## \u003ca name=\"get-started\"\u003e\u003c/a\u003eGetting Started\n\nTo get started, first make sure you have [Deno](https://deno.land) installed and configured.\n\n### Quick Start\n\nIn your application, import the Zoic module from the deno.land [module](https://deno.land/x/zoic).\n\n```typescript\nimport { Zoic } from 'https://deno.land/x/zoic/zoic.ts';\n```\n\n### Create a cache\n\nInitialize a new `Zoic` object, passing in your user defined `options` object. If no `options` object is passed, `Zoic` will set all properties to their default values.\n\n- `cache`: Sets cache eviction policy, options being `'LRU'`, `'LFU'`, and `'Redis'`. *Default value:* `'LRU'`\n- `expire`: Sets cache invalidation/expiration time for each entry. This can be set in human readable time, as a comma separated string, denoting hours with value followed by `'h'`, minutes followed by `'m'`, and seconds followed by `'s'`. Alternatively, you may pass in the time as a `number` representing seconds. *Default value:* `Infinity`\n- `capacity`: Sets the maximum number of entries. *Default value:* `Infinity`\n- `respondOnHit`: Determines if cache hits should be sent as an HTTP response immediately upon retrieval. If this is set to `false`, the cached response data will be attached to Oak `Context.state` property, `context.state.zoicResponse`. It is recommended to leave this set to `true`, unless additional processing on the response data is desired in the event of a cache hit. *Default value:* `true`\n\n\nExample:\n\n```typescript\nconst cache = new Zoic({\n  cache: 'LFU',\n  expire: '5m, 3s',\n  capacity: 50,\n});\n```\n\n### Redis cache\n\nTo use an instance of Redis as your cache, initialize a new `Zoic` object, passing in `'Redis'` as the `cache` property on your options object. You also must specify the port your instance of Redis is running on, via the `port` property. Optionally, you may pass the hostname as well. This value defaults to `'127.0.0.1'`.\n\u003cbr\u003e\n\u003cbr\u003e\nNOTE: Options `expire` and `capacity` do not have an effect on `Zoic` if using Redis, as these would be defined in your Redis configuration.\n\u003cbr\u003e\n\u003cbr\u003e\nExample:\n```typescript\nconst cache = new Zoic({\n  cache: 'redis',\n  port: 6379\n});\n```\n\n\n## \u003ca name=\"middleware\"\u003e\u003c/a\u003eMiddleware and caching\n\n### Zoic.use()\n`Zoic.use()` is responsible for both sending cached responses, and storing responses in the cache. When `.use()` is called in a middleware chain, it will check if data exists in the cache at a key representing that route's endpoint. If the query is successful, it will send an HTTP response with the cached body, headers, and status. If the query is unsucessful, `.use()` will automatically listen for when the subsequent middleware in that route has been executed, and will cache the contents of the HTTP response before being sent to the client. This way, the developer only needs to place `.use()` in their middleware chain at the point where they would like the response to be sent in the event of a cache hit, making it extremely easy to use.\n\u003cbr\u003e\n\u003cbr\u003e\nNOTE: if the user has selected `false` for `respondOnHit` when initializing `Zoic`, the response data will be stored on `ctx.state.zoicResponse` instead of being sent as an HTTP response.\n\u003cbr\u003e\n\u003cbr\u003e\nExample:\n\n```typescript\nconst cache = new Zoic();\n\nrouter.get('/userInfo/:name', cache.use, controller.dbRead, ctx =\u003e {\n    ctx.response.headers.set('Content-Type', 'application/json');\n    ctx.response.body = ctx.state.somethingFromYourDB;\n});\n```\n### Zoic.put()\n`Zoic.put()` will add responses to the cache without first querying to see if an entry already exists. The primary use being to replace data at an already existing keys, or manually add responses without anything being returned. Like with `.use()`, `.put()` will automatically store the response body, headers, and status at the end of a middleware chain before the response is sent.\n\u003cbr\u003e\n\u003cbr\u003e\nExample:\n\n```typescript\nconst cache = new Zoic();\n\nrouter.put('/userInfo/:name', cache.put, controller.dbWrite, ctx =\u003e {\n    ctx.response.body = ctx.state.someDataYouChanged;\n});\n```\n### Zoic.clear()\n`Zoic.clear()` clears the contents of the cache.\n\u003cbr\u003e\n\u003cbr\u003e\nExample:\n\n```typescript\nconst cache = new Zoic();\n\n// On its own..\nrouter.post('/userInfo/:name', cache.clear);\n\n// In conjunction with another function...\nrouter.post('/otherUserInfo/', cache.clear, controller.dbWrite, ctx =\u003e {\n    ctx.response.body = ctx.state.someFreshData;\n});\n```\n## \u003ca name=\"authors\"\u003e\u003c/a\u003eAuthors\n\n- [Joe Borrow](https://github.com/jmborrow)\n- [Celena Chan](https://github.com/celenachan)\n- [Aaron Dreyfuss](https://github.com/AaronDreyfuss)\n- [Hank Jackson](https://github.com/hankthetank27)\n- [Jasper Narvil](https://github.com/jnarvil3)\n- [unkn0wn-root](https://github.com/unkn0wn-root)\n\n## \u003ca name=\"license\"\u003e\u003c/a\u003eLicense\n\nThis product is licensed under the MIT License - see the LICENSE file for details.\n\nThis is an open source product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foslabs-beta%2Fzoic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foslabs-beta%2Fzoic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foslabs-beta%2Fzoic/lists"}