[QUESTION]: responseCachePlugin sessionId and PUBLIC scope #8021
-
|
Hi, I had a question in regards to the sessionId option and the PUBLIC scope of queries being cached. This is fine for PRIVATE scope of queries, but in regards to PUBLIC scope of queries, I notice that it will cache individual public queries based on the sessionId. In my case, it shouldn't include the sessionId in the keyData since the queries aren't private and should return the same for any user. I am unable to access the PRIVATE scope value in the sessionId to return a null value if its not PRIVATE. I assume this behavior is normal, is there any reason for it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@simplecommerce this is intentional behavior. the importantly though, it does not create per-user entries for PUBLIC queries. all logged-in users share the same PUBLIC cache entry, and all logged-out users share another. the actual so the worst case for PUBLIC queries is 2 cache entries (null session vs non-null session), not N entries per user. if you want PUBLIC queries to always share a single entry regardless of auth state, return responseCachePlugin({
sessionId: (requestContext) => {
// only use session for private queries
const token = requestContext.request.http?.headers.get('authorization');
return token ?? null;
},
})the response cache plugin docs explain the caching behavior and scope interaction in more detail. |
Beta Was this translation helpful? Give feedback.
@simplecommerce this is intentional behavior. the
responseCachePluginsplits PUBLIC cache entries into two buckets: one for requests wheresessionIdreturnsnull(logged out users) and one where it returns a non-null value (logged in users).importantly though, it does not create per-user entries for PUBLIC queries. all logged-in users share the same PUBLIC cache entry, and all logged-out users share another. the actual
sessionIdvalue is only used as the cache key for PRIVATE-scoped queries.so the worst case for PUBLIC queries is 2 cache entries (null session vs non-null session), not N entries per user.
if you want PUBLIC queries to always share a single entry regardless of auth state,…