Describe the problem
The current Cloudflare adapter uses Cloudflare's Cache API to cache and return responses. This is really useful for cutting down on response time when pages are rendered often and are mostly static.
However, if you have a site which has different responses based on per-user state or settings, such as session state, then this caching behavior can't be used at all because any response could be different depending on the user. We can't even only cache when the user is logged out (often the most common case) because then a logged in user may receive a cached response where they are logged out.
This is partially resolved by setting the cache-control: private header, which bypasses the cache in Cloudflare and keeps local caching on the client, but it still means we can't use Cloudflare's cache and the logic for it just becomes dead weight for every request.
Describe the proposed solution
Ideally we would be able to add a function call prior to checking the cache to see if we should check the cache. For instance, in the user session case, you could add a call to check if the request has a session cookie, and if not check the cache for the not-logged-in version of the response.
I think generally most use cases would be around cookies, so the logic could just be checking for the presence of certain cookies, but it might be nice to have it be more generalized too.
Alternatives considered
Keep existing caching logic and use cache-control: private for all routes. If you happen to have a site without any session state, then the cache can be used, otherwise you can only rely on local caching.
Importance
would make my life easier
Additional Information
This could be applicable to other adapters, I'm not 100% sure as I haven't had a chance to check.
Describe the problem
The current Cloudflare adapter uses Cloudflare's Cache API to cache and return responses. This is really useful for cutting down on response time when pages are rendered often and are mostly static.
However, if you have a site which has different responses based on per-user state or settings, such as session state, then this caching behavior can't be used at all because any response could be different depending on the user. We can't even only cache when the user is logged out (often the most common case) because then a logged in user may receive a cached response where they are logged out.
This is partially resolved by setting the
cache-control: privateheader, which bypasses the cache in Cloudflare and keeps local caching on the client, but it still means we can't use Cloudflare's cache and the logic for it just becomes dead weight for every request.Describe the proposed solution
Ideally we would be able to add a function call prior to checking the cache to see if we should check the cache. For instance, in the user session case, you could add a call to check if the request has a session cookie, and if not check the cache for the not-logged-in version of the response.
I think generally most use cases would be around cookies, so the logic could just be checking for the presence of certain cookies, but it might be nice to have it be more generalized too.
Alternatives considered
Keep existing caching logic and use
cache-control: privatefor all routes. If you happen to have a site without any session state, then the cache can be used, otherwise you can only rely on local caching.Importance
would make my life easier
Additional Information
This could be applicable to other adapters, I'm not 100% sure as I haven't had a chance to check.