Skip to content

future cache vs value cache #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

future cache vs value cache #82

wants to merge 2 commits into from

Conversation

craig-day
Copy link

This fixes #45 by updating the CacheMap signature to reflect how it is really used. This also resolves #59 by introducing a new concept, the CacheStore.

The CacheMap stores futures/promises for results, so it can be synchronous and prevents us from queueing multiple load calls. It isn't straightforward to adjust this to just store values, because we can't store a value in the cache until the load has completed, so we would end up issuing every load during a request instead of re-using a load.

My proposed solution is to add a second layer of caching. The first layer of cache, L1, still stores the CompletableFuture that will eventually contain the result, so we don't issue multiple load calls. The new layer, L2, is where the CacheStore comes in. The general algorithm works something like this:

if L1 contains key
  return value from L1

else
  result = new promise for data

  if L2 contains key
    promiseFromL2 = get key from L2
    when promiseFromL2 is complete, complete result

  else
    promiseFromLoad = issue load request
    when promiseFromLoad is complete, store result in cache
    when cache store is complete, complete result

  store result in L1

  return result

@craig-day
Copy link
Author

/cc @bbakerman

@bbakerman
Copy link
Member

Thanks very much for this excellent PR - I am sorry I have taken so long to get back. I missed this in my emails.

I need to check this out and really do some strong investigation on it but I think it looks like it does what is says, breaking the caching of values from the caching of futures pointing to values.

This is a breaking change. The reason is the change of from a cache of <K,CompletableFurure>. I know there is no way around that.

I started (but pretty much abort) and effort to make a 3.x here : #62

Ideally we could make all the breaking changes in one new version. The other big change is moving DataLoader itself to be an interface rather than a class.

@bbakerman bbakerman changed the base branch from master to 2_2_3_branch June 27, 2021 10:43
@bbakerman bbakerman changed the base branch from 2_2_3_branch to pre_3x_work June 27, 2021 10:46
@bbakerman bbakerman changed the base branch from pre_3x_work to branch_before_3x_work June 27, 2021 10:49
@bbakerman
Copy link
Member

I edited this PR to make it a diff against the older code before I started recently on 3.x work.

This way I can once again see the diff more clearly.

I will look into this code and see if we can incorporate it back into an upcoming 3.x release

This contains a small breaking change, that is the future cache is changed in its signature.

It was always a little confused <K,V> but really <K,CompletrableFuture<V> in practice so maybe its not a big problem

bbakerman added a commit that referenced this pull request Jun 28, 2021
@bbakerman bbakerman mentioned this pull request Jun 28, 2021
@bbakerman
Copy link
Member

@craig-day

Can you have a look at #88 - its pretty much this code with some tweaks and it merges into the lastest master

@bbakerman bbakerman closed this Jul 5, 2021
@craig-day craig-day deleted the craig-day/future-cache-vs-value-cache branch July 5, 2021 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do I store the cache to a remote server CacheMap<K, V> is the wrong signature
2 participants