← Back to README · Documentation index
SharedCache demonstrates exceptional HTTP standards compliance, fully adhering to established web caching specifications.
Complete compliance features:
- Cache Control Directives: Proper handling of
no-store,no-cache,private,public,s-maxage, andmax-age - HTTP Method Support: Standards-compliant caching for GET/HEAD methods with correct rejection of non-cacheable methods
- Status Code Handling: Appropriate caching behavior for 200, 301, 404 responses and proper rejection of 5xx errors
- Vary Header Processing: Full content negotiation support with intelligent cache key generation
- Conditional Requests:
Cache.match()returns304for matchingIf-None-Match/If-Modified-Sinceon fresh entries;createFetchrevalidates with the origin and handles304 Not Modified
- stale-while-revalidate: Background revalidation with immediate stale content serving
- stale-if-error: Graceful degradation serving cached content during network failures
- Fault Tolerance: Robust error handling and recovery mechanisms
SharedCache implements a subset of the standard Web Cache API interface, focusing on core caching operations:
interface Cache {
match(request: RequestInfo | URL): Promise<Response | undefined>; // ✅ Implemented
put(request: RequestInfo | URL, response: Response): Promise<void>; // ✅ Implemented
delete(request: RequestInfo | URL): Promise<boolean>; // ✅ Implemented
// Not implemented - throw "not implemented" errors
add(request: RequestInfo | URL): Promise<void>; // ❌ Throws error
addAll(requests: RequestInfo[]): Promise<void>; // ❌ Throws error
keys(): Promise<readonly Request[]>; // ❌ Throws error
matchAll(): Promise<readonly Response[]>; // ❌ Throws error
}Implementation status:
- ✅ Core Methods:
match(),put(),delete()- Fully implemented with HTTP semantics - ❌ Convenience Methods:
add(),addAll()- Useput()instead - ❌ Enumeration Methods:
keys(),matchAll()- Not available in server environments
createFetch vs Cache: createFetch adds SWR, origin revalidation, and status headers. Bare cache.match() / cache.put() are storage-style APIs (expired entries return undefined without createFetch).
createFetch vs createCacheHandler: Same caching core. createFetch wraps outbound fetch; createCacheHandler accepts an in-process origin callback.
Options parameter differences:
match() and delete() support ignoreMethod only—the same subset as the Cloudflare Workers Cache API. To ignore query strings, set cacheKeyRules.search: false. To bypass Vary processing, set sharedCache.ignoreVary: true.
| Standard | Status | Coverage |
|---|---|---|
| RFC 7234 (HTTP Caching) | ✅ Fully Compliant | 100% |
| RFC 5861 (stale-* extensions) | ✅ Fully Compliant | 100% |
| Web Cache API | ✅ Subset Implementation | Core Methods |
| WinterCG Standards | ✅ Fully Supported | 100% |
- Professional HTTP Semantics: Powered by
http-cache-semanticsfor RFC compliance - Configurable Cache Keys: Rules for URL parts, cookies, headers, and custom fragments
- Robust Error Handling: Comprehensive exception handling with graceful degradation
- Performance Optimized: Efficient storage backends with configurable TTL
- Privacy Compliance: Correct handling of
privatedirective for user-specific content - Shared Cache Optimization: Priority given to
s-maxageovermax-agefor multi-user environments - Authorization Header Handling: Automatic compliance with HTTP specification - responses to requests with
Authorizationheaders are not cached in shared caches unless explicitly permitted by response cache control directives - Cache Isolation: Proper separation of cached content based on user context and authentication state
- Secure Defaults: Conservative caching policies with explicit opt-in for sensitive operations
🔒 Important Security Note: SharedCache automatically enforces HTTP caching security rules. Requests containing Authorization headers will not be cached unless the response explicitly allows it with directives like public, s-maxage, or must-revalidate. This ensures compliance with shared cache security requirements.
SharedCache is production-ready and battle-tested, providing enterprise-grade HTTP caching with full standards compliance for server-side applications.