When a Cached File Result Becomes Stale

Caching a parsed result by path alone can return old data when the same path begins naming updated content.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a modified report
  2. Choose a freshness contract
  3. Compare name, metadata and content identity under replacement
  4. Include parser behavior in a parsed-result key

Trace a modified report

Reading daily.csv first yields three rows. Replacing that file with four rows leaves the path identical. A result cache needs some rule for deciding whether the stored result is still valid.

Choose a freshness contract

Metadata, a content fingerprint, or explicit invalidation may be appropriate depending on cost and consistency requirements. Test replacements as well as in-place edits. Content and metadata explain why each signal describes something different.[1]

Compare name, metadata and content identity under replacement

A generated report can change while staying at the same path. A cache keyed only by path returns the old result. Modification time and size can detect some changes, while a digest identifies content differences according to the chosen digest model. See metadata updates.

Path report.csv unchanged
Old bytes ABC, new bytes XYZ
Both lengths 3
A byte digest normally distinguishes them even if metadata is identical

Include parser behavior in a parsed-result key

Same bytes can produce another result after a schema or encoding change. Combine a content identity with relevant parser settings when the cache stores decoded data. Test replacement by same-length bytes and metadata-only changes.

References

  1. Python Software Foundation, io: Core Tools for Working with Streams ↩