{"id":15637421,"url":"https://github.com/anderscan/cache-controlled","last_synced_at":"2025-08-03T19:32:09.149Z","repository":{"id":190478640,"uuid":"682283125","full_name":"AndersCan/cache-controlled","owner":"AndersCan","description":"yet another cache-control parser","archived":false,"fork":false,"pushed_at":"2023-09-11T20:51:54.000Z","size":267,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-04T21:39:47.386Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndersCan.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":"2023-08-23T20:53:14.000Z","updated_at":"2023-08-23T20:54:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"f43f5150-4ad7-44a0-991c-6668d5c257ee","html_url":"https://github.com/AndersCan/cache-controlled","commit_stats":null,"previous_names":["anderscan/cache-controlled"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndersCan%2Fcache-controlled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndersCan%2Fcache-controlled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndersCan%2Fcache-controlled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndersCan%2Fcache-controlled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndersCan","download_url":"https://codeload.github.com/AndersCan/cache-controlled/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246243564,"owners_count":20746307,"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-03T11:11:36.929Z","updated_at":"2025-03-29T20:41:13.532Z","avatar_url":"https://github.com/AndersCan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cache-controlled\n\nSimplifies working with `Cache-Control` headers\n\n## Parse\n\nParse a `cache-control` header. Parsing is case insensitive and all spaces are ignored.\n\n```js\nimport { parse } from \"cache-controlled\";\n\nparse( \"max-age=10\" );\n// { \"max-age\": 10 }\nparse( \"public, max-age=10, stale-while-revalidate=600\" );\n// { \"max-age\": 10, public: true, \"stale-while-revalidate\": 600 }\n\n// For convenience, also handles `undefined` and `string[]`\nparse( undefined ); // {}\nparse( [ \"public\", \"max-age=10\" ] ); // { \"max-age\": 10, public: true }\n```\n\n\u003e Note: `parse` also adds a `timestamp` field used by `check`.\n\n## Check\n\n`check` will tell you if you can still use your cached content:\n\n- `ok`: Cache is ok. No need to do anything\n- `okStale`: Cache is ok, but stale. Fetch update\n- `okError`: Cache is ok IFF you had/have a network error\n\n```js\nconst status = check( parse( \"max-age=10\" ) ).ok; // true\n// If the `immutable` directive is present, it will always return `true`\nconst status = check( parse( \"immutable\" ) ).ok; // true\nconst status = check( parse( \"stale-while-revalidate=10\" ) ).ok; // false\nconst status = check( parse( \"stale-while-revalidate=10\" ) ).okStale; // true\nconst status = check( parse( \"stale-if-error=10\" ) ).okError; // true\n```\n\n_Note: `check` only reads `immutable`, `max-age`, and `stale-` directives._\n\n```js\nconst status =\n  check( parse( \"immutable, must-revalidate, no-store, no-cache\" ) ).ok; // true\n```\n\n## string\n\nHelper to write a typesafe cache control header\n\n```js\nstring( \"public, max-age=10, stale-while-revalidate=600\" );\n// public, max-age=10, stale-while-revalidate=600\n\n// Unknown keys won't be filtered out\n// @ts-expect-error typo - should be `max-age`\nstring( \"maxage=1\" ); // never\n// @ts-expect-error missing value\nstring( \"maxage\" ); // never\n```\n\n## stringify\n\n```js\nstringify( { public: true, \"max-age\": 10, \"stale-while-revalidate\": 600 } );\n// public,max-age=10,stale-while-revalidate=600\n\n// Unknown keys won't be filtered out\n// @ts-expect-error Unknown key\nstringify( { unknown: 42 } ); // unknown=42\n```\n\n## Other libraries\n\nIf you need to handle all headers related to HTTP caching, check out [http-cache-semantics](https://www.npmjs.com/package/http-cache-semantics).\n\nThis library is more compareable to [cache-control-parser](https://github.com/etienne-martin/cache-control-parser)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderscan%2Fcache-controlled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanderscan%2Fcache-controlled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderscan%2Fcache-controlled/lists"}