Limits
Layeron Cache builds on Cloudflare Cache and inherits its edge runtime behavior. Design cache usage around predictable keys, reusable responses, and explicit invalidation.
Cacheable Responses
Section titled “Cacheable Responses”Cache works best for responses that are safe to reuse:
| Response Type | Guidance |
|---|---|
| Public JSON | Good fit with TTL and tags. |
| Localized JSON | Good fit with accept-language in vary. |
| HTML pages | Good fit when auth and personalization are handled carefully. |
| Per-user data | Use very small scope and deliberate vary dimensions. |
| Mutation responses | Usually purge related reads after the mutation. |
Keep sensitive user-specific responses under narrow keys. Include a stable tenant or user dimension in the key when a response is scoped.
Key Cardinality
Section titled “Key Cardinality”Every vary header and query parameter can increase the number of entries. Keep keys stable:
- Use short vary lists.
- Prefer low-cardinality headers.
- Keep query parameters meaningful.
- Use shorter TTLs for search and autocomplete.
- Attach tags to entries that need coordinated invalidation.
Response Bodies
Section titled “Response Bodies”put stores a Response in Cloudflare Cache. When route code needs to return
the same response object, clone it before writing:
const response = Response.json({ products })
await apiCache.put(request, response.clone(), { tags: ["products"],})
return responseTags are metadata for invalidation. They should be stable strings:
[ "products", "product:123", "tenant:acme",]Use compact tags and avoid raw user input. If a tag comes from user or tenant data, normalize it through your application ID format.
Stats Timing
Section titled “Stats Timing”Stats are updated by the Cache product runtime. In Workers, updates may be scheduled through the request execution context. A response can be returned to the client while the stats update is still completing.
For tests that assert exact counter values, wait for the runtime’s background work to settle.