How to memoize field policy read functions?

I want read field policies to be called only when they depend on data that has changed since their last invocation. Basically, I want my queries that depend on derived fields to be faster. They are slow right now because field policy read functions are called every time a query to the cache is made requesting that field. Some of these derived fields are very expensive to compute, and I do not yet see a way to know when I can reuse an old value or when I have to calculate a new one.

My ideas

  1. Manually create a dependency array for each read field policy and save the values of these variables with the result of a computation in storage so I can check to see if any of these variables have changed values on the next read field policy invocation to determine if i need to recompute the value or use the old one.

  2. Use an entirely different state management library that can track these dependencies for me and handle the propagation of state updates efficiently. Jotai is my top contender for this one. “Atoms” (nodes representing pieces of state that can be connected to one another) would have to be kept in sync with the apollo cache, which I plan to do by updating atoms in the merge field policy. This way my expensive, derived state is handled outside of apollo but still sees the updates to the underlying data residing in the apollo cache.

(2) is my favorite idea, but I would rather this concept be implemented in apollo as all my data is already there.

My Questions

  1. Can this be done with the current feature set of apollo?
  2. How can I determine whether or not the values a read field policy depends on have changed?
  3. What other strategies might I consider to solve this problem?