Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:2giosangmitom Sqmeow nvim View Caching

From Leeroopedia
Knowledge Sources
Domains View_Processing, Session_Management
Last Updated 2026-10-16 14:00 GMT

Overview

A view generation principle that orders view requests independently of their computation, discarding stale results so only the latest request's view is committed.

Description

View Caching is the principle of managing concurrent view computations (filter, sort, aggregate) on a retained result so that only the most recent user request is committed, and stale results from superseded requests are silently discarded. A generation counter is incremented for each view request; the computation commits only if its generation is still current when it finishes.

This principle addresses the challenge of rapid user interaction: a user may change filters several times in quick succession, and earlier (slower) computations may finish after later (faster) ones. Without generation gating, a stale result could overwrite a newer view. The begin_view / finish_view pair ensures that only the latest request's view is committed and its notification is sent.

The view state is stored as a View enum: Rows(Arc<Vec<usize>>) for filter/sort results (row indices), or Aggregate(Arc<ResultSet>) for aggregation results (new DataFrame). The view is stored under a short lock; existing readers may keep an Arc to an older view safely.

Usage

Use this principle when a UI allows rapid changes to a view: assign a generation to each request, and commit only if the generation is still current.

Theoretical Basis

The principle uses a generation counter as a compare-and-swap gate:

  1. begin_view: Increment the generation counter; return the new value.
  2. Computation: Run the filter/sort/aggregate work (may take time).
  3. finish_view(generation, finish): If the current generation matches, call finish() (which commits the view and emits the event). If not, the result is silently discarded — the view and its Lua specification are not changed.
# Abstract pattern (NOT real implementation):
class Call:
    view: Mutex[View | None]
    generation: Mutex[int]

    def begin_view(self) -> int:
        gen = self.generation.lock().increment()
        return gen

    def finish_view(self, gen: int, finish: Callable):
        with self.generation.lock() as current:
            if current == gen:  # still the latest request
                finish()  # commit view, emit event
            # else: stale — silently discard

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment