{"id":24419021,"url":"https://github.com/badbatch/cacheability","last_synced_at":"2025-04-12T06:05:13.850Z","repository":{"id":24768461,"uuid":"102401203","full_name":"badbatch/cacheability","owner":"badbatch","description":"A utility class to parse, store and print http cache headers.","archived":false,"fork":false,"pushed_at":"2024-11-24T22:54:30.000Z","size":1555,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T06:04:53.297Z","etag":null,"topics":["cache-control","cacheability","etag","headers","http","parser"],"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/badbatch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-09-04T20:47:56.000Z","updated_at":"2024-11-24T22:54:30.000Z","dependencies_parsed_at":"2023-12-16T01:24:24.404Z","dependency_job_id":"8d306af5-6ac9-4e4a-aaa7-396719c406db","html_url":"https://github.com/badbatch/cacheability","commit_stats":null,"previous_names":["bad-batch/cacheability"],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbatch%2Fcacheability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbatch%2Fcacheability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbatch%2Fcacheability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badbatch%2Fcacheability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badbatch","download_url":"https://codeload.github.com/badbatch/cacheability/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525143,"owners_count":21118618,"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":["cache-control","cacheability","etag","headers","http","parser"],"created_at":"2025-01-20T09:17:04.204Z","updated_at":"2025-04-12T06:05:13.792Z","avatar_url":"https://github.com/badbatch.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cacheability\n\nA utility class to parse, store and print http cache headers.\n\n[![Build and publish](https://github.com/badbatch/cacheability/actions/workflows/build-and-publish.yml/badge.svg)](https://github.com/badbatch/cacheability/actions/workflows/build-and-publish.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n[![npm version](https://badge.fury.io/js/cacheability.svg)](https://badge.fury.io/js/cacheability)\n\n## Installation\n\n```bash\nnpm add cacheability\n```\n\n## Documentation\n\n### Initialization\n\nThe constructor takes either a Headers instance, object literal of header key/values, cache-control header field value\nor Cacheability metadata object, parses it, if required, and then stores the result on the Cacheability instance's\nmetadata property.\n\n```javascript\nimport { Cacheability } from \"cacheability\";\n\nconst headers = new Headers({\n  \"cache-control\": \"public, max-age=60\",\n  \"content-type\": \"application/json\",\n  \"etag\": \"33a64df551425fcc55e4d42a148795d9f25f89d4\",\n});\n\nconst cacheability = new Cacheability({ headers });\n\nconst { cacheControl, etag, ttl } = cacheability.metadata;\n// cacheControl is { maxAge: 60, public: true }\n// etag is 33a64df551425fcc55e4d42a148795d9f25f89d4\n// ttl is 1516060712991 if Date.now is 1516060501948\n```\n\n### Properties\n\n#### metadata\n\nThe property holds the Cacheability instance's parsed cache headers data, including cache control directives, etag,\nand a derived TTL timestamp.\n\n### Methods\n\n#### checkTTL\n\nThe method checks whether the TTL timestamp stored in the Cacheability instance is still valid, by comparing it to the\ncurrent timestamp.\n\n```javascript\nconst cacheability = new Cacheability({ cacheControl: \"public, max-age=3\" });\n\n// One second elapses...\n\nconst isValid = cacheability.checkTTL();\n// isValid is true\n\n// Three seconds elapse...\n\nconst isStillValid = cacheability.checkTTL();\n// isStillValid is false\n```\n\n#### printCacheControl\n\nThe method prints a cache-control header field value based on the Cacheability instance's metadata. The max-age and/or\ns-maxage are derived from the TTL stored in the metadata.\n\n```javascript\nconst cacheability = new Cacheability({ cacheControl: \"public, max-age=60, s-maxage=60\" });\n\n// Five seconds elapse...\n\nconst cacheControl = cacheability.printCacheControl();\n// cacheControl is \"public, max-age=55, s-maxage=55\"\n```\n\n## Changelog\n\nCheck out the [features, fixes and more](CHANGELOG.md) that go into each major, minor and patch version.\n\n## License\n\nCacheability is [MIT Licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadbatch%2Fcacheability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadbatch%2Fcacheability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadbatch%2Fcacheability/lists"}