MCPcopy Create free account
hub / github.com/dwgx/WindsurfAPI / cacheSet

Function cacheSet

src/cache.js:151–171  ·  view source on GitHub ↗
(key, value)

Source from the content-addressed store, hash-verified

149}
150
151export function cacheSet(key, value) {
152 if (!isCacheEnabled()) return;
153 // Don't cache empty or partial results
154 if (!value || (!value.text && !(value.chunks && value.chunks.length))) return;
155 const bytes = valueBytes(value);
156 const limit = maxBytes();
157 deleteEntry(key);
158 if (!Number.isFinite(bytes) || bytes > limit) {
159 _stats.skips++;
160 return;
161 }
162 _store.set(key, { value, expiresAt: Date.now() + TTL_MS, bytes });
163 _bytes += bytes;
164 _stats.stores++;
165 while (_store.size > MAX_ENTRIES || _bytes > limit) {
166 const oldest = _store.keys().next().value;
167 if (oldest === undefined) break;
168 deleteEntry(oldest);
169 _stats.evictions++;
170 }
171}
172
173export function cacheStats() {
174 const total = _stats.hits + _stats.misses;

Callers 4

cache.test.jsFile · 0.90
nonStreamResponseFunction · 0.90
handlerFunction · 0.90

Calls 4

isCacheEnabledFunction · 0.85
valueBytesFunction · 0.85
maxBytesFunction · 0.85
deleteEntryFunction · 0.85

Tested by

no test coverage detected