Conversation
Saving a JsonConfig used to cache.clear(), evicting every cached page so that every visualization recomputed its graph on its next origin miss. Now a save deletes exactly the pages of that slug. Page cache keys depend on the scheme, host, path, query string and Vary headers of the request that stored them, and this code runs at several live URLs, so reconstructing keys from a slug is guesswork. Instead the real keys are recorded when Django stores the page: the view mixin tags the request with the slug, and PageCacheRegistryMiddleware, listed above UpdateCacheMiddleware so it runs after the store, asks get_cache_key for the key a later viewer will hit and appends it to a per-slug registry in the same cache. purge_vis_cache deletes the registered keys. Every doubtful case falls back to clearing everything, so a purge can be wasteful but never leaves a stale page: no registry for the slug, a registry that overflowed, or a registry lock that could not be taken. Registry updates are serialized across gunicorn workers with a lock file in the cache directory, since the misses for a slug's URLs arrive together right after a purge and a lost update would strand a page. Cache hits never run the view, so they carry no tag and the middleware returns immediately: the zero-database hit path is unchanged. Election pages keep the clear-everything purge; their views are untagged. Tests view pages through two different hosts and schemes and assert the save evicts all of them while another visualization stays cached and is still served with zero queries. The headless cache tests now also assert that updating another visualization leaves this one cached. Both test classes start from an empty page cache, since the file cache outlives tests. The purge tests live in their own module because testSimple.py hit pylint's 1000-line limit. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013JDT5wxbhPUtZG1kXPZ1Xe
Django's default evicts a random third of the cache on every write once 300 files exist. Each cached page costs two files, so the default held about 150 pages, fewer than the URL variants of a dozen busy visualizations, and each eviction is a graph recomputation at the origin. A page cache registry evicted this way also forces the next purge to clear everything. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013JDT5wxbhPUtZG1kXPZ1Xe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.