샘플
http-cache-semantics 4.3.0: CachePolicy, CachePolicy.storable, CachePolicy.stale
검증된 샘플 — npm http-cache-semantics 4.3.0: CachePolicy, CachePolicy.storable, CachePolicy.stale. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:81aa90e528785d4293dae39801fcd3a6a6a3bc1a0e53e0eb4d05667aab145824
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node linux 24 · ubuntu · glibc 2.39 x64 node npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-10-17 |
케이스
HOW- 목표
- verify pkg:npm/http-cache-semantics@4.3.0
- 심벌
-
- CachePolicy
- CachePolicy.storable
- CachePolicy.stale
- CachePolicy.timeToLive
- CachePolicy.satisfiesWithoutRevalidation
- CachePolicy.revalidationHeaders
- CachePolicy.revalidatedPolicy
- CachePolicy.toObject
- CachePolicy.fromObject
- 환경
- node
- 생성일
- 2026-10-17T23:42:28Z
컨트랙트
- CachePolicy.storable evaluates whether an HTTP response can be stored in cache according to Cache-Control headers
- CachePolicy.stale and CachePolicy.timeToLive evaluate whether a cached HTTP response has expired based on max-age
- CachePolicy.satisfiesWithoutRevalidation determines if a cached response can satisfy a new incoming HTTP request
- CachePolicy.revalidationHeaders generates conditional request headers including if-none-match for 304 revalidation
- CachePolicy.revalidatedPolicy returns updated policy instance merging cached headers with 304 revalidation response headers
- CachePolicy.toObject and CachePolicy.fromObject serialize and restore policy state
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/http-cache-semantics@4.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/http-cache-semantics@4.3.0
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:86cd9831f7974ccc828601407b3134153528a0864e929376dd12b7337e76388e","contract":["CachePolicy.storable evaluates whether an HTTP response can be stored in cache according to Cache-Control headers","CachePolicy.stale and CachePolicy.timeToLive evaluate whether a cached HTTP response has expired based on max-age","CachePolicy.satisfiesWithoutRevalidation determines if a cached response can satisfy a new incoming HTTP request","CachePolicy.revalidationHeaders generates conditional request headers including if-none-match for 304 revalidation","CachePolicy.revalidatedPolicy returns updated policy instance merging cached headers with 304 revalidation response headers","CachePolicy.toObject and CachePolicy.fromObject serialize and restore policy state"],"goal":"verify pkg:npm/http-cache-semantics@4.3.0","kind":"HOW","packages":["pkg:npm/http-cache-semantics@4.3.0"],"schemaVersion":1,"symbols":["CachePolicy","CachePolicy.storable","CachePolicy.stale","CachePolicy.timeToLive","CachePolicy.satisfiesWithoutRevalidation","CachePolicy.revalidationHeaders","CachePolicy.revalidatedPolicy","CachePolicy.toObject","CachePolicy.fromObject"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/http-cache-semantics@4.3.0"],"schemaVersion":1,"subject":"pkg:npm/http-cache-semantics@4.3.0","symbols":["CachePolicy","CachePolicy.storable","CachePolicy.stale","CachePolicy.timeToLive","CachePolicy.satisfiesWithoutRevalidation","CachePolicy.revalidationHeaders","CachePolicy.revalidatedPolicy","CachePolicy.toObject","CachePolicy.fromObject"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-http-cache-semantics",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-http-cache-semantics",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"http-cache-semantics": "4.3.0"
}
},
"node_modules/http-cache-semantics": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.3.0.tgz",
"integrity": "sha512-M5t5LlJpS1UHMjvwRQVdFHvPISGeLAxNcrWuJkeGh0KxsqCHZ1O3NXZU/8x7cD0BDcGW8kapxMKTvwlqrNkHkA==",
"license": "BSD-2-Clause"
}
}
}
{
"name": "sample-http-cache-semantics",
"version": "1.0.0",
"private": true,
"description": "verify pkg:npm/http-cache-semantics@4.3.0",
"type": "module",
"main": "src/index.mjs",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"http-cache-semantics": "4.3.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/http-cache-semantics@4.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/http-cache-semantics@4.3.0"
]
}
import CachePolicy from 'http-cache-semantics';
export { CachePolicy };
export function createCachePolicy(request, response, options) {
return new CachePolicy(request, response, options);
}
export function isResponseStorable(request, response, options) {
const policy = new CachePolicy(request, response, options);
return policy.storable();
}
export function isCacheFresh(policy) {
return !policy.stale();
}
export function canSatisfyRequest(policy, request) {
return policy.satisfiesWithoutRevalidation(request);
}
export function getRevalidationHeaders(policy, request) {
return policy.revalidationHeaders(request);
}
export function applyRevalidation(policy, revalidationRequest, revalidationResponse) {
return policy.revalidatedPolicy(revalidationRequest, revalidationResponse);
}
import assert from 'node:assert/strict';
import CachePolicy from 'http-cache-semantics';
import {
createCachePolicy,
isResponseStorable,
isCacheFresh,
canSatisfyRequest,
getRevalidationHeaders,
applyRevalidation,
} from '../src/index.mjs';
function runContract() {
const req = {
url: 'https://example.com/api/items',
method: 'GET',
headers: {
accept: 'application/json',
},
};
const resFresh = {
status: 200,
headers: {
'cache-control': 'public, max-age=3600',
etag: '"v1-etag"',
'last-modified': 'Wed, 21 Oct 2025 07:28:00 GMT',
'content-type': 'application/json',
},
};
// 1. CachePolicy.storable evaluates whether an HTTP response can be stored in cache according to Cache-Control headers
const policyFresh = createCachePolicy(req, resFresh);
assert.strictEqual(policyFresh.storable(), true);
assert.strictEqual(isResponseStorable(req, resFresh), true);
const resNoStore = {
status: 200,
headers: {
'cache-control': 'no-store',
},
};
assert.strictEqual(isResponseStorable(req, resNoStore), false);
// 2. CachePolicy.stale and timeToLive evaluate whether a cached HTTP response has expired based on max-age
assert.strictEqual(policyFresh.stale(), false);
assert.strictEqual(isCacheFresh(policyFresh), true);
assert.strictEqual(policyFresh.timeToLive() > 0, true);
const resStale = {
status: 200,
headers: {
'cache-control': 'public, max-age=0',
etag: '"v1-etag"',
},
};
const policyStale = createCachePolicy(req, resStale);
assert.strictEqual(policyStale.stale(), true);
assert.strictEqual(isCacheFresh(policyStale), false);
// 3. CachePolicy.satisfiesWithoutRevalidation determines if a cached response can satisfy a new incoming HTTP request
assert.strictEqual(canSatisfyRequest(policyFresh, req), true);
assert.strictEqual(
canSatisfyRequest(policyFresh, {
url: 'https://example.com/api/items',
method: 'POST',
headers: { accept: 'application/json' },
}),
false
);
assert.strictEqual(canSatisfyRequest(policyStale, req), false);
// 4. CachePolicy.revalidationHeaders generates conditional request headers including if-none-match for 304 revalidation
const revalHeaders = getRevalidationHeaders(policyStale, req);
assert.strictEqual(revalHeaders['if-none-match'], '"v1-etag"');
// 5. CachePolicy.revalidatedPolicy returns updated policy instance merging cached headers with 304 revalidation response headers
const revalReq = {
url: 'https://example.com/api/items',
method: 'GET',
headers: revalHeaders,
};
const revalRes = {
status: 304,
headers: {
'cache-control': 'public, max-age=7200',
etag: '"v1-etag"',
},
};
const revalidated = applyRevalidation(policyStale, revalReq, revalRes);
assert.strictEqual(revalidated.matches, true);
assert.strictEqual(revalidated.modified, false);
assert.strictEqual(revalidated.policy.storable(), true);
assert.strictEqual(revalidated.policy.stale(), false);
// 6. CachePolicy.toObject and CachePolicy.fromObject serialize and restore policy state
const obj = policyFresh.toObject();
const restored = CachePolicy.fromObject(obj);
assert.strictEqual(restored.storable(), true);
assert.strictEqual(restored.stale(), false);
assert.deepStrictEqual(restored.responseHeaders()['content-type'], 'application/json');
}
runContract();
오리진 시더
익명