Is client cache aware of header or directive value changes?

I’m working on establishing a localization pattern for my enterprise graph and so far I’m leaning towards leveraging the accept-language header. However, in some of my research, people say the client cache will not be aware of header changes - in this case the browser/device locale settings changes. I’ve also considered a custom directive to handle locale, which I assume the client cache will also not be aware of since it builds cache keys based on operations and input arguments.

Suppose I was to leverage input arguments, which I’d rather not. In that case, I assume the client cache would recognize input argument changes and would automatically refetch relevant operations.

Alternatively, if I leverage headers and/or directives, the client cache would not be aware when the values change. At best, the operations fetching localized fields would have to be manually refetched. And, at worst, the cache would need to be cleared and/or the app would need to reloaded to handle a locale change.

Thoughts?

Thanks for asking this @tylergoelz. Stay tuned. We will get a reply here asap.

1 Like

Hi @tylergoelz! Good to see you! I think there’s a way to do this with Apollo Client, but it would likely be a bit hacky and implementation-dependent. My first instinct would be to do a full page refresh on locale change. I would not act on that instinct if I knew/expected users to frequently change their locale. But when I internationalized our Apollo Client-powered app at my last job, that was our approach.

Your question reminded me of a PR we ultimately closed without merging. @jerelmiller’s comment is helpful in illustrating the issue:

2 Likes

Super helpful @JeffAuriemma - thanks for the response. I’ll use this in my ADR pro/cons for headers and directive options

2 Likes