Download test_cache.cjs from PabloRod11/quantlab-probability-research: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/PabloRod11/quantlab-probability-research/resolve/main/test_cache.cjs
- Command line
-
hf download hf://spaces/PabloRod11/quantlab-probability-research/test_cache.cjs
-
curl -L -o test_cache.cjs https://huggingface.co/spaces/PabloRod11/quantlab-probability-research/resolve/main/test_cache.cjs
1.01 kB
| const assert=require('node:assert/strict'); | |
| const {createRunCache}=require('./cache.js'); | |
| let now=0;const cache=createRunCache({now:()=>now,maxEntries:3,ttlMs:600000}); | |
| assert.equal(cache.get('missing'),null); | |
| const report={probabilities:[.1,.2,.7]};cache.set('a',report);report.probabilities[0]=9; | |
| assert.equal(cache.get('a').probabilities[0],.1); | |
| const hit=cache.get('a');hit.probabilities[0]=8;assert.equal(cache.get('a').probabilities[0],.1); | |
| cache.set('b',{});cache.set('c',{});cache.get('a');cache.set('d',{});assert.equal(cache.get('b'),null);assert.ok(cache.get('a')); | |
| now=600000;assert.equal(cache.get('a'),null,'Expiration is based on creation, not extended by cache hits'); | |
| assert.equal(cache.size(),0);cache.set('new',{});cache.clear();assert.equal(cache.size(),0); | |
| assert.equal(createRunCache().get('a'),null,'A new tab instance cannot see old cache entries'); | |
| assert.throws(()=>createRunCache({maxEntries:0})); | |
| console.log('Cache tests passed: TTL, LRU cap, independent instances, cloning, clear'); | |