サンプル
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
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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);
});
オリジンシーダー
匿名