Skip to content

Surgical Django cache purge#609

Open
skaphan wants to merge 3 commits intoartoonie:mainfrom
skaphan:surgical-cache-purge
Open

Surgical Django cache purge#609
skaphan wants to merge 3 commits intoartoonie:mainfrom
skaphan:surgical-cache-purge

Conversation

@skaphan
Copy link
Contributor

@skaphan skaphan commented Mar 11, 2026

Summary

  • Replaces cache.clear() with surgical purge that only deletes cache entries for the affected slug's URLs
  • Uses thread-local middleware to capture request host for accurate cache key reconstruction
  • Catches DisallowedHost instead of temporarily mutating settings.ALLOWED_HOSTS (addresses review concern from Fix server-side cache to work with conditional GET #608)
  • Comprehensive test verifies all URL variants (including query-string vistypes) are purged

Follow-up optimization to #608. This is a nice-to-have, not critical — #608's cache.clear() is correct and safe.

Test plan

  • test_purge_vis_cache_clears_all_cached_urls — populates cache for base, embedded, and query-string URLs, purges by slug, verifies all gone
  • test_purge_django_cache_tries_www_variant — verifies www. domain variant is included in purge domains

🤖 Generated with Claude Code

with open(filenames.ONE_ROUND, 'r', encoding='utf-8') as f:
self.client.post('/upload.html', {'jsonFile': f})
config = TestHelpers.get_latest_upload()
path = reverse('visualize', args=(config.slug,))

Check notice

Code scanning / CodeQL

Unused local variable

Variable path is not used.
skaphan added 3 commits March 20, 2026 18:11
Uses thread-local middleware to capture the current request host,
then builds synthetic requests matching each cached URL to delete
only the affected cache entries instead of clearing everything.

Co-Authored-By: Claude Opus 4.6
Replace temporary ALLOWED_HOSTS mutation with DisallowedHost
catch-and-skip to avoid modifying security settings at runtime.
Replace two separate purge tests with one comprehensive test that
verifies purge_vis_cache clears all cached URL variants for a slug,
including query-string variants.

Co-Authored-By: Claude Opus 4.6
@skaphan skaphan force-pushed the surgical-cache-purge branch from 7029d2a to 9916f83 Compare March 20, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant