๐Ÿ”ฅ Warm Cache

Warm Cache

Keep capacity data hot with a background poller. Eliminates cold-start penalty on your first call.

Usage

const flash = new VaeaFlash({
  apiUrl: 'https://api.vaea.fi',
  connection,
  wallet,
  preWarm: true,  // polls /v1/capacity every 2s
});

// First getCapacity() is instant โ€” data already cached
const capacity = await flash.getCapacity();

// When done, clean up the background poller
flash.destroy();

What Gets Cached

DataWithout Warm CacheWith Warm Cache
Borrowing capacity~20ms (API call)Instant
Token routes~20ms (API call)Instant
Fee quotes~20ms (API call)Instant
Protocol health~20ms (API call)Instant
โ„น๏ธ Note
The poller runs every 2 seconds in the background. Data is always fresh for MEV/arbitrage use cases.

Advanced API

For bots that need direct access to the Warm Cache instance:

typescript
import { WarmCache } from '@vaea/flash';

const cache = new WarmCache('https://api.vaea.fi', 2000);
await cache.start(); // first refresh is synchronous

// Check if cache has data
console.log(cache.isWarm());  // true

// Get cached data instantly
const capacity = cache.getCapacity();

// Get a single token
const sol = cache.getTokenCapacity('SOL');
console.log(sol?.max_amount, sol?.status);

// Listen for updates (called every 2s)
cache.onUpdate((newCapacity) => {
  console.log('Cache updated:', newCapacity.tokens.length, 'tokens');
});

// Cleanup
cache.stop();
MethodReturnsDescription
start()Promise<void>Start polling โ€” first refresh is synchronous
stop()voidStop background polling
isWarm()booleanWhether cache has data loaded
getCapacity()CapacityResponse | nullGet all cached capacity data
getTokenCapacity(symbol)TokenCapacity | nullGet capacity for a single token
onUpdate(handler)voidRegister a listener for capacity updates
๐Ÿ’ก Tip
Always call cache.stop() / flash.destroy() when shutting down to stop the background poller and prevent resource leaks.