Edge cache#341
Open
nanaabdul1172 wants to merge 4 commits into
Open
Conversation
- Add stripUserContent() function to remove HTML and bidi controls - Remove U+202A-U+202E (LRE, RLE, PDF, LRO, RLO) characters - Remove U+2066-U+2069 (LRI, RLI, FSI, PDI) characters - Preserve all printable Unicode, emoji, and ZWJ sequences - Add 26 comprehensive tests covering bidi removal and content preservation - Fix adversarial content vulnerability that breaks UI trust
- Add Cache-Control headers (s-maxage=60, stale-while-revalidate=120) to GET endpoints - Implement cache-tag based purging for Fastly/Vercel/Cloudflare - Create NearbyCacheControlInterceptor for nearby queries with geohash-based tags - Create GistIdCacheControlInterceptor for single gist queries - Add purgeCdnTags() method to CacheService for CDN invalidation - Update gists service to trigger CDN purge on gist creation - Add CDN_PURGE_ENDPOINT and CDN_PURGE_TOKEN config to .env.example - Include comprehensive implementation documentation Resolves cache-control headers requirement for GET /gists scaling
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.
closes #150
Files Created/Modified
NEW:
cache-control.interceptor.ts
Created interceptors that add Cache-Control and Cache-Tag headers
NearbyCacheControlInterceptor for nearby gist queries (uses geohash-based tags)
GistIdCacheControlInterceptor for single gist queries (uses ID-based tags)
Headers: Cache-Control: s-maxage=60, stale-while-revalidate=120
MODIFIED:
gists.controller.ts
Applied NearbyCacheControlInterceptor to GET /gists endpoint
Applied GistIdCacheControlInterceptor to GET /gists/:id endpoint
Cache tags generated dynamically based on request parameters
MODIFIED:
gists.service.ts
Updated invalidateNearbyCache() to call CDN purge when new gists are posted
Purges cache tags like gist:nearby:{geohash_cell}
MODIFIED:
cache.service.ts
Added purgeCdnTags() method supporting Fastly, Vercel, and Cloudflare
Gracefully degrades if CDN config not present
MODIFIED:
gists.module.ts
Registered interceptors as providers for dependency injection
MODIFIED:
.env.example
Added CDN_PURGE_ENDPOINT and CDN_PURGE_TOKEN configuration
NEW:
CACHE_CONTROL_IMPLEMENTATION.md
Comprehensive documentation of the implementation
✅ Acceptance Criteria Met
✅ Response bears both Cache-Control and Cache-Tag headers
✅ Post a new gist → purge the tag → CDNs revalidate
✅ Implementation in
gists.controller.ts
✅ Created
cache-control.interceptor.ts
🎯 How It Works
GET requests receive headers:
Cache-Control: s-maxage=60, stale-while-revalidate=120
Cache-Tag: gist:nearby:{geohash} (for nearby queries)
Cache-Tag: gist:one:{id} (for single gist queries)
POST requests trigger:
Redis cache invalidation (existing behavior)
CDN purge via API call to configured endpoint
Tag-based purging ensures only affected caches are invalidated
Cache tags use geohash for nearby queries, so all queries in the same ~153m cell share cache and purge together
🔧 Configuration
Add to .env (optional, degrades gracefully if not set):
CDN_PURGE_ENDPOINT=https://api.fastly.com/service/{service_id}/purge
CDN_PURGE_TOKEN=your_api_token
✅ Verified
No TypeScript compilation errors
All dependencies properly injected
GeoService correctly used for geohash computation
Backward compatible (works without CDN configuration)