WarUI

Block cache with LRU eviction

GRID-A04-F05P0baselineShippedexperimental

Bound the loaded blocks of a remote grid and watch old blocks get evicted.

Live example

Expected behavior

Loaded blocks are listed as loaded. Moving past the limit evicts the least recently used unprotected block and logs blockEvicted. Returning to it refetches it.

Source

const api = createGrid({
  rows: [],
  columns,
  rowModel: 'remote',
  blockSize: 100,
  maxCachedBlocks: 5,
  evictionPolicy: 'lru',
  protectBlock: (block) => block.index === focusedBlock,
  remoteSource: { fetchWindow },
});
api.on('blockEvicted', ({ index }) => log(`Block ${index} evicted`));
console.log(api.getCacheState().blocks);

API reference

GRID-A04-F05 API
KindNameTypeDescription
OptionmaxCachedBlocks—Maximum unprotected loaded blocks.
OptionevictionPolicy—'lru' or 'distance'.
OptionprotectBlock—Returns true to keep a block cached.
EventblockEvicted—Fires when a block is evicted.
MethodgetCacheState—Lists blocks with index, state and lastAccess.

Acceptance criteria

  • The cache never holds more than maxCachedBlocks unprotected blocks. (met)
  • Blocks intersecting the viewport are never evicted. (met)
  • Blocks holding the focused row, rows being edited, or unsaved optimistic rows are never evicted. (met)
  • An evicted block is refetched on demand with a new request. (met)
  • getCacheState returns, for each block, its index, state and lastAccess. (met)