{"id":17921827,"url":"https://github.com/3axap4ehko/socket-cache","last_synced_at":"2026-03-03T17:04:17.670Z","repository":{"id":57365065,"uuid":"341064497","full_name":"3axap4eHko/socket-cache","owner":"3axap4eHko","description":"NodeJS socket cache","archived":false,"fork":false,"pushed_at":"2024-05-15T00:03:55.000Z","size":546,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-16T14:02:40.105Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/3axap4eHko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["3axap4eHko","zource-dev"],"patreon":"zource","custom":["https://paypal.me/3axap4eHko"]}},"created_at":"2021-02-22T03:07:25.000Z","updated_at":"2024-05-30T02:16:42.416Z","dependencies_parsed_at":"2023-09-24T02:30:08.307Z","dependency_job_id":"88d60bd2-417a-4745-8900-b6532327e577","html_url":"https://github.com/3axap4eHko/socket-cache","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"a38011eaef6bfad0e9dd93fe73f88aca2f6547f9"},"previous_names":[],"tags_count":127,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fsocket-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fsocket-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fsocket-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fsocket-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3axap4eHko","download_url":"https://codeload.github.com/3axap4eHko/socket-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240831380,"owners_count":19864718,"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":[],"created_at":"2024-10-28T20:36:20.015Z","updated_at":"2026-03-03T17:04:17.601Z","avatar_url":"https://github.com/3axap4eHko.png","language":"TypeScript","funding_links":["https://github.com/sponsors/3axap4eHko","https://github.com/sponsors/zource-dev","https://patreon.com/zource","https://paypal.me/3axap4eHko"],"categories":[],"sub_categories":[],"readme":"# Socket Cache\n\nBlazing fast HTTP network socket caching library for NodeJS\n\n[![Coverage Status][codecov-image]][codecov-url]\n[![Github Build Status][github-image]][github-url]\n[![NPM version][npm-image]][npm-url]\n[![Downloads][downloads-image]][npm-url]\n[![Snyk][snyk-image]][snyk-url]\n\n## Usage\n\nCreate inmemory cache\n```typescript\n// cache.js\nimport { cache } from 'socket-cache';\n\ninterface CacheKey {\n  id: string | undefined;\n  expiresIn: number;\n}\n\ninterface CacheValue {\n  value: Buffer[];\n  expiresAt: number;\n}\n\nconst storage = new Map\u003cstring, CacheValue\u003e();\n\nexport default createCache\u003cCacheKey\u003e({\n  mapToKey: ({ url }) =\u003e ({ id: url, expiresIn: 1000 }),\n  set(key, value) {\n    if (key.id) {\n      const expiresAt = Date.now() + key.expiresIn;\n      storage.set(key.id, { value, expiresAt });\n    }\n  },\n  get(key) {\n    if (key.id \u0026\u0026 storage.has(key.id)) {\n      const { value, expiresAt } = storage.get(key.id);\n      if (expiresAt \u003e Date.now()) {\n        return value;\n      }\n      storage.delete(key.id);\n    }\n    return null;\n  }\n});\n```\n\nCached server\n```typescript\nimport http from 'http';\nimport cache from './cache';\n\nconst hostname = '127.0.0.1';\nconst port = 3000;\n\nconst server = http.createServer((req, res) =\u003e {\n  const isCached = await cache(req, res);\n  if (!isCached) {\n    next();\n  } else {\n    res.statusCode = 200;\n    res.setHeader('Content-Type', 'text/plain');\n    res.end(`Hello World ${new Date()}`);\n  }\n});\n\nserver.listen(port, hostname, () =\u003e {\n  console.log(`Server running at http://${hostname}:${port}/`);\n});\n```\n\n## License\nLicense [The MIT License](http://opensource.org/licenses/MIT)\nCopyright (c) 2023 Ivan Zakharchanka\n\n[npm-url]: https://www.npmjs.com/package/socket-cache\n[downloads-image]: https://img.shields.io/npm/dw/socket-cache.svg?maxAge=43200\n[npm-image]: https://img.shields.io/npm/v/socket-cache.svg?maxAge=43200\n[github-url]: https://github.com/3axap4eHko/socket-cache/actions/workflows/build.yml\n[github-image]: https://github.com/3axap4eHko/socket-cache/actions/workflows/build.yml/badge.svg?branch=master\n[codecov-url]: https://codecov.io/gh/3axap4eHko/socket-cache\n[codecov-image]: https://codecov.io/gh/3axap4eHko/socket-cache/branch/master/graph/badge.svg?maxAge=43200\n[snyk-url]: https://snyk.io/test/npm/socket-cache/latest\n[snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/3axap4eHko/socket-cache.svg?maxAge=43200\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3axap4ehko%2Fsocket-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3axap4ehko%2Fsocket-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3axap4ehko%2Fsocket-cache/lists"}