Skip to content

Cache: invalidate a cache=True source when its data changes #39

Open

Description

@jvdd

Problem

A source registered with cache=True asserts that its data is static for the process lifetime. Nothing checks that. The response cache, the cube cache, the resolved min/max bounds and the sorted flag on LFQueryBuilder all live until the process ends or the source is re-registered with raw data or a new builder. Re-registering the same builder object invalidates nothing and only warns (flexviz/server.py, register_source).

Architecture.md and the register_source docstring cite issue #27 for this. #27 is a pull request. This issue replaces that reference.

Proposal

Pick one of:

  1. A fingerprint per source (file size and mtime for a local Parquet scan; the frame id for a resident frame), checked on each request and used to drop every cache entry keyed on that source when it changes.
  2. An explicit invalidate(name) endpoint and CLI command, with no automatic check.

Option 2 is smaller and keeps the static-data contract explicit. Option 1 is what a user who edits a file expects.

Done when

  • A changed file behind a cache=True scan is served fresh after invalidation, including its bounds and sorted flag.
  • Re-registering the same builder object with cache=True drops the stale entries instead of warning.
  • The docs name the chosen behaviour and the limits.

Activity

  1. jvdd commented on Oct 1, 2026

    @jvdd
    ContributorAuthor

    Finding from the review of #141: the Polars scan goes stale too, not only the FlexViz caches.

    Repro (pure Polars 1.44.2, no FlexViz):

    import os, numpy as np, polars as pl
    
    def write(path, level, n=200_000):
        pl.select(power=level + pl.Series(np.random.default_rng(1).random(n))).write_parquet(path)
    
    write("a.parquet", 10.0)
    lf = pl.scan_parquet("a.parquet")
    lf.select(pl.col("power").max()).collect(engine="streaming")   # 10.99...
    write("a.parquet.tmp", 100.0); os.replace("a.parquet.tmp", "a.parquet")
    lf.select(pl.col("power").max()).collect(engine="streaming")   # PanicException: Invalid argument (os error 22)
    pl.scan_parquet("a.parquet").select(pl.col("power").max()).collect(engine="streaming")   # 100.99...

    An in-place overwrite fails in the same way. After the first collect, the scan_parquet LazyFrame keeps the metadata of the old file. A new scan reads the new file.

    Through FlexViz (a source registered with scan_parquet, mounted, file replaced while the server runs):

    • cache=False: every /dashboard/update returns 500, from a panic in the streaming Parquet source. The panels stay empty.
    • cache=True: a new page shows the old first view.

    Consequence for this issue: dropping the FlexViz caches does not make a changed file readable through the registered LazyFrame. Invalidation must also rebuild the scan. Until then, the docs tell users to restart the server after the data changes (web apps guide in #141).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions