샘플
toad-cache 3.7.4: LruObject
검증된 샘플 — npm toad-cache 3.7.4: LruObject. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: new LruObject() defaults to max=1000, ttl=0, size=0…
sha256:8b7abd9b9ad834f64fbb7d00f7b39d7bae34e34e3ac0e8c800987a97c1e4aac6
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-11-29 |
케이스
HOW- 목표
- verify toad-cache.LruObject in pkg:npm/toad-cache@3.7.4
- 패키지
- 심벌
-
- toad-cache.LruObject
- 환경
- node 22.23.2
- 생성일
- 2026-11-29T21:34:30Z
컨트랙트
- new LruObject() defaults to max=1000, ttl=0, size=0, and returns undefined for missing keys
- new LruObject(max, ttlInMsecs) rejects negative or non-integer max with 'Invalid max value' and invalid ttlInMsecs with 'Invalid ttl value'
- get() and overwriting set() promote an entry to most-recently-used so capacity overflow evicts the least-recently-used entry
- null-prototype backing storage handles keys named 'toString' and 'constructor' without colliding with Object.prototype
- getMany(), keys(), evict(), delete(), deleteMany(), and clear() maintain accurate entries and size
- max=0 disables capacity eviction
- ttlInMsecs>0 records a numeric expiry via expiresAt() and removes expired entries on get() returning undefined
파일
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
소스
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 toad-cache.LruObject in pkg:npm/toad-cache@3.7.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/toad-cache@3.7.4
Demonstrate these symbols/APIs:
- toad-cache.LruObject
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:82efd25aa6add9e19d7e374f08df85c8908142ecccf093593840d2a66ee66ab0","constraints":{"executionContext":"node"},"contract":["new LruObject() defaults to max=1000, ttl=0, size=0, and returns undefined for missing keys","new LruObject(max, ttlInMsecs) rejects negative or non-integer max with 'Invalid max value' and invalid ttlInMsecs with 'Invalid ttl value'","get() and overwriting set() promote an entry to most-recently-used so capacity overflow evicts the least-recently-used entry","null-prototype backing storage handles keys named 'toString' and 'constructor' without colliding with Object.prototype","getMany(), keys(), evict(), delete(), deleteMany(), and clear() maintain accurate entries and size","max=0 disables capacity eviction","ttlInMsecs\u003e0 records a numeric expiry via expiresAt() and removes expired entries on get() returning undefined"],"goal":"verify toad-cache.LruObject in pkg:npm/toad-cache@3.7.4","kind":"HOW","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"symbols":["toad-cache.LruObject"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"subject":"pkg:npm/toad-cache@3.7.4","symbols":["toad-cache.LruObject"],"verifierAdapter":"node-typescript@1"}
'use strict';
const { LruObject } = require('toad-cache');
function createLruCache(max, ttlInMsecs) {
return new LruObject(max, ttlInMsecs);
}
module.exports = {
createLruCache,
LruObject,
};
{
"name": "toad-cache-lru-object-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "toad-cache-lru-object-sample",
"version": "1.0.0",
"dependencies": {
"toad-cache": "3.7.4"
}
},
"node_modules/toad-cache": {
"version": "3.7.4",
"resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.4.tgz",
"integrity": "sha512-m1TdR/rvT7kgGJZhspNtXdsdYk0fddFpJJFlG5s+UkPFo6lkLoZ3YLOaovPYjq1R75NP5JfeTlSHaOsE09peCg==",
"license": "MIT",
"engines": {
"node": ">=20"
}
}
}
}
{
"name": "toad-cache-lru-object-sample",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"description": "Minimal sample verifying toad-cache.LruObject in toad-cache@3.7.4",
"main": "index.js",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"toad-cache": "3.7.4"
}
}
{
"schemaVersion": 1,
"goal": "verify toad-cache.LruObject in pkg:npm/toad-cache@3.7.4",
"kind": "HOW",
"packages": [
"pkg:npm/toad-cache@3.7.4"
],
"symbols": [
"toad-cache.LruObject"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const assert = require('node:assert/strict');
const { setTimeout: delay } = require('node:timers/promises');
const { createLruCache, LruObject } = require('../index.js');
async function main() {
// 1. Default constructor values
const defaultCache = new LruObject();
assert.equal(defaultCache.max, 1000);
assert.equal(defaultCache.ttl, 0);
assert.equal(defaultCache.size, 0);
assert.equal(defaultCache.get('missing'), undefined);
assert.equal(defaultCache.expiresAt('missing'), undefined);
// 2. Constructor parameter validation
assert.throws(() => new LruObject(-1), { message: 'Invalid max value' });
assert.throws(() => new LruObject(1.5), { message: 'Invalid max value' });
assert.throws(() => new LruObject(10, -1), { message: 'Invalid ttl value' });
assert.throws(() => new LruObject(10, 0.5), { message: 'Invalid ttl value' });
// 3. LRU eviction order and recency promotion via get() and set()
const cache = createLruCache(2, 0);
cache.set('a', 1);
cache.set('b', 2);
assert.equal(cache.size, 2);
assert.equal(cache.expiresAt('a'), 0);
// Reading 'a' promotes it to most-recently-used; inserting 'c' evicts 'b'
assert.equal(cache.get('a'), 1);
cache.set('c', 3);
assert.equal(cache.size, 2);
assert.equal(cache.get('b'), undefined);
assert.equal(cache.get('a'), 1);
assert.equal(cache.get('c'), 3);
// Updating an existing key replaces its value and bumps it to most-recently-used
cache.set('a', 10);
assert.equal(cache.size, 2);
cache.set('d', 4);
assert.equal(cache.get('c'), undefined);
assert.equal(cache.get('a'), 10);
assert.equal(cache.get('d'), 4);
assert.deepEqual(cache.keys().sort(), ['a', 'd']);
// 4. Null-prototype storage avoids collisions with Object.prototype keys
const protoCache = createLruCache(3, 0);
assert.equal(protoCache.get('toString'), undefined);
protoCache.set('toString', 'custom-value');
protoCache.set('constructor', 'ctor-value');
assert.equal(protoCache.get('toString'), 'custom-value');
assert.equal(protoCache.get('constructor'), 'ctor-value');
// 5. Batch operations, explicit evict(), delete(), deleteMany(), clear()
const opsCache = createLruCache(4, 0);
opsCache.set('k1', 'v1');
opsCache.set('k2', 'v2');
opsCache.set('k3', 'v3');
assert.deepEqual(opsCache.getMany(['k2', 'missing', 'k1']), ['v2', undefined, 'v1']);
// Least-recently-used is now 'k3' (k2 and k1 were bumped by getMany)
opsCache.evict();
assert.equal(opsCache.get('k3'), undefined);
assert.equal(opsCache.size, 2);
opsCache.set('k4', 'v4');
opsCache.delete('k2');
assert.equal(opsCache.get('k2'), undefined);
assert.equal(opsCache.size, 2);
opsCache.deleteMany(['k1', 'nonexistent']);
assert.equal(opsCache.get('k1'), undefined);
assert.equal(opsCache.size, 1);
opsCache.clear();
assert.equal(opsCache.size, 0);
assert.deepEqual(opsCache.keys(), []);
// 6. Unlimited capacity when max === 0
const unlimited = createLruCache(0, 0);
unlimited.set('x', 1);
unlimited.set('y', 2);
unlimited.set('z', 3);
assert.equal(unlimited.size, 3);
// 7. TTL expiration removes stale entries on get()
const ttlCache = createLruCache(5, 30);
const beforeSet = Date.now();
ttlCache.set('ephemeral', 'fresh');
const expiry = ttlCache.expiresAt('ephemeral');
assert.equal(typeof expiry, 'number');
assert.ok(expiry >= beforeSet + 30);
assert.equal(ttlCache.get('ephemeral'), 'fresh');
await delay(60);
assert.equal(ttlCache.get('ephemeral'), undefined);
assert.equal(ttlCache.size, 0);
console.log('toad-cache.LruObject contract passed');
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
오리진 시더
익명