convoyinc / apollo-cache-hermes

A cache implementation for Apollo Client, tuned for performance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrent access from multiple instances

pardeike opened this issue · comments

I am looking for an implementation that allows us to use Apollo in multiple apps on iOS. Each app is going to talk to the same endpoint (or at least share object ids with the other apps) thus creating a seemless experience across apps. For that, and to allow for offline data, we would like to have one common file location that all apps (via App Groups) can cache the common entities.

However, I wonder if concurrent cache access and detecting changes is possible with hermes. I expect the access to at least overlap for a few seconds when you switch between apps that access or update the cache since iOS allows an app to continue execute in the background for a short period of time before it goes into hibernation.

I am willing to work with the source but I would like to get some feedback first before I dig deeper.

Thanks,
Andreas

I don't know if hermes will really solve this for you (no more than any other pure-JS cache implementation would, at least). Hermes (and Apollo's default implementation) load the entire cache into the memory; there's no back and forth with the disk beyond that point.

Since, AFAIK, you can't perform RPC between iOS apps: you would need to serialize the cache to disk (in a shared location, like one managed via an app group) when switching between apps.

I'm also assuming you're in a react native world? The other unfortunate reality is that shuffling data along RN's bridge is pretty expensive, so you want to minimize the amount of time spent hydrating/dehydrating cache data.

Due to all that, I don't think concurrent access is really feasible with hermes :(

That said, it might be feasible to refactor hermes to track diffs between past "save points", so that you can minimize the time spent saving/restoring state between app switches. Synchronizing those deltas across multiple apps might get tricky, though.