Skip to content

Value cache support #88

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

Merged
merged 5 commits into from
Jul 5, 2021
Merged

Value cache support #88

merged 5 commits into from
Jul 5, 2021

Conversation

bbakerman
Copy link
Member

@bbakerman bbakerman commented Jun 28, 2021

This is a re-implementation of the PR that is #82

Both are trying to fix the issue outlined in Issue #45

It adds support for an external value cache as well as the previous local CompletableFuture cache.

It's basically the same code with some renames (I preferred the names) and also with extra documentation.

I also fixed a couple of edge case bugs that I found from more extensive testing

But it retains most of the code from the original PR and the idea of a 2 level cache.

This PR is technically a small breaking change. The signature of CacheMap has changed to reflect that it is in fact a cache of futures and not pure values (see #45). It is not anticipated that this will cause major problems but it is breaking and hence this needs to go out in a 3.x major version

@@ -70,7 +72,7 @@
*
* @return the cached value, or {@code null} if not found (depends on cache implementation)
*/
V get(U key);
CompletableFuture<V> get(K key);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The small brekaing change.

It was always a CompleteableFuture at runtime but now the signature reflects this more correctly

Copy link

@craig-day craig-day left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing this back in! I'd love to see my name as a co-author on the commit if reasonable :D Happy to see this moving again regardless though.

}


@SuppressWarnings("unchecked")
private CacheMap<Object, CompletableFuture<V>> determineCacheMap(DataLoaderOptions loaderOptions) {
return loaderOptions.cacheMap().isPresent() ? (CacheMap<Object, CompletableFuture<V>>) loaderOptions.cacheMap().get() : CacheMap.simpleMap();
private CacheMap<Object, V> determineCacheMap(DataLoaderOptions loaderOptions) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named determineFutureCache? I'm also not sure why we need to cast it and enforce a key type of object. Can't we use the K type erasure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cache key that is looked up is actually and opaque object to it needs to be this.

The naming can be changed however

}

@SuppressWarnings("unchecked")
private CachedValueStore<Object, V> determineCacheStore(DataLoaderOptions loaderOptions) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same observation and question here. Should this be called determineCachedValueStore and can we leave it as <K, V> instead of casting K to Object?

@bbakerman
Copy link
Member Author

@tinnou / @andimarek

I would really appreciate your views on this

* @author <a href="https://github.com/craig-day">Craig Day</a>
*/
@PublicSpi
public interface CachedValueStore<K, V> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must say I am not really convinced of the name, but I also don't anything better out of my head :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about secondLevelCache?

private final StatisticsCollector stats;
private final CacheMap<Object, V> futureCache;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so maybe FutureCache is a better name than CacheMap?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but that would definitely break everyone using it.

I want that better name but I am willing to wear the non breaking API change

Copy link
Member

@andimarek andimarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some naming stuff, see comments.

But more importantly: this is a very specific implementation for a two level cache. Is it possible to find a more general abstraction and this two level cache is just one possible implementation? (I have not looked into it, so the answer maybe no)

@bbakerman bbakerman merged commit 7e2e609 into master Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants