Remove Django server-side response cache#605
Closed
skaphan wants to merge 5 commits intoartoonie:mainfrom
Closed
Conversation
Add updated_at field to JsonConfig model, use ConditionalGetMixin for all visualization views, and short-circuit 304 responses in VisualizeEmbedded before expensive computation.
Add proper cache control for embedded visualizations
- Add pylint disable for too-few-public-methods (it is a mixin) - Add docstring to get() method - Rename last_modified/if_modified_since to camelCase Co-Authored-By: Claude Opus 4.6
Full HTTP response caching is handled by Cloudflare at the edge.
The Django file-based cache middleware was redundant and added
complexity (vary_on_headers hack, cache.clear() on every save).
- Remove UpdateCacheMiddleware and FetchFromCacheMiddleware
- Replace file-based CACHES with LocMemCache (still needed for rate limiting)
- Remove vary_on_headers('increment') from Visualize and VisualizeBallotpedia
- Remove cache.clear() from cloudflare.py and Movie.save()
- Remove test_cache_speed and test_cache_works (tested removed behavior)
Co-Authored-By: Claude Opus 4.6
Co-Authored-By: Claude Opus 4.6
Owner
Author
|
Superseded by #608 which fixes the server-side cache instead of removing it. |
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.

Why remove Django's server-side response cache
The Django file-based cache middleware (
UpdateCacheMiddleware/FetchFromCacheMiddleware) was the original mechanism for avoiding redundant graph computation on repeated page loads. It served that purpose, but it is now redundant and counterproductive given the current architecture:1. Cloudflare already handles edge caching
Dynamic pages are cached at Cloudflare's CDN, which handles the high-traffic case (millions of requests during bursts). The
ConditionalGetMixinreturns 304 when content has not changed, so even cache misses at Cloudflare skip expensive graph computation. The Django middleware is a second cache layer that does not add meaningful value.2. The middleware requires workarounds that add complexity
vary_on_headers('increment')-- decorates several views with aVaryheader for a fake HTTP header that no client ever sends. This is a no-op (every request has the same empty value, so it never affects caching) and can be removed as dead code.cache.clear()incloudflare.pyandMovie.save()-- every CDN purge and movie save also had to clear the local Django cache. These become dead code.DISABLE_CACHEenvironment variable -- needed for development/testing to work around the cache. Goes away entirely.3. It causes confusing behavior during development and testing
Stale cached responses make it hard to tell whether code changes are taking effect. We hit this directly while testing the friendly-embed-404 change -- the cache was serving old responses and masking the actual view behavior.
4. What we keep
ConditionalGetMixinfor 304 responses (unchanged, with linter fixes in Fix linter issues in ConditionalGetMixin #604)LocMemCachefor upload rate limiting (the only actual use ofdjango.core.cachein views.py)Summary of changes
UpdateCacheMiddlewareandFetchFromCacheMiddlewarefrom MIDDLEWAREvary_on_headers('increment')from Visualize and VisualizeBallotpedia (was a no-op)cache.clear()fromcloudflare.pyandMovie.save()test_cache_speedandtest_cache_works(tested the removed middleware behavior)cache,patch,get_data_for_view)Net effect: 5 files changed, ~120 lines removed, no new code.
Test plan