Skip to content

Limits

Layeron Cache builds on Cloudflare Cache and inherits its edge runtime behavior. Design cache usage around predictable keys, reusable responses, and explicit invalidation.

Cache works best for responses that are safe to reuse:

Response TypeGuidance
Public JSONGood fit with TTL and tags.
Localized JSONGood fit with accept-language in vary.
HTML pagesGood fit when auth and personalization are handled carefully.
Per-user dataUse very small scope and deliberate vary dimensions.
Mutation responsesUsually 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.

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.

put stores a Response in Cloudflare Cache. When route code needs to return the same response object, clone it before writing:

Terminal window
const response = Response.json({ products })
await apiCache.put(request, response.clone(), {
tags: ["products"],
})
return response

Tags are metadata for invalidation. They should be stable strings:

Terminal window
[
"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 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.