Skip to content

Edge cache#341

Open
nanaabdul1172 wants to merge 4 commits into
VertexChainLabs:mainfrom
nanaabdul1172:Edge-cache
Open

Edge cache#341
nanaabdul1172 wants to merge 4 commits into
VertexChainLabs:mainfrom
nanaabdul1172:Edge-cache

Conversation

@nanaabdul1172

Copy link
Copy Markdown
Contributor

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)

nanaabdul1172 and others added 4 commits July 18, 2026 10:00
- 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
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.

Add Vercel Edge-Cache friendly revalidation tags for findNearby

1 participant