Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hello 👋 It's my understanding that setting a Value Cache does not disable the default in-memory cache map. Is this correct?

If so, what is the official supported way to perform caching exclusively via the Value Cache? Is it .setCacheMap(null).setValueCache(myValueCache)?

You must be logged in to vote

Replies: 1 comment · 4 replies

Comment options

The method org.dataloader.DataLoaderOptions#cachingEnabled controls Future caching - that is an in memory map of CompletableFutures was have returned before per key. The naming could be better but was invented when we ONLY had a futures cache and no value cache.

So you would do

DataLoaderOptions options = DataLoaderOptions.newOptions().setCachingEnabled(false).setValueCache(myValueCache);
You must be logged in to vote
4 replies
@bbakerman
Comment options

A better ideal world of naming would have

DataLoaderOptions options = DataLoaderOptions.newOptions().setFutureCachingEnabled(false).setValueCache(myValueCache);

but backwards compatibility matters

@kirkobyte
Comment options

Hi @bbakerman 👋 I had tried this out locally, and it seemed like setCachingEnabled(false) also disabled the ValueCache.

When I set up my DataLoader with this configuration, breakpoints set in MemcachedValueCache never got hit:

    return RegisteredLoader.builder()
        .name(EditorialQualityScoreLoader.NAME)
        .dataLoader(
            DataLoaderFactory.newMappedDataLoader(
                new MyLoader(myClient),
                DataLoaderOptions.newOptions()
                    .setCachingEnabled(false)
                    .setValueCache(
                        new MemcachedValueCache<>(
                            memcacheClient, EditorialQualityScores.class, getTtl(environment)))
                    .setMaxBatchSize(MAX_BATCH_SIZE)))
        .build();

However, I did manage to find a workaround, by setting the CacheMap to this NoopCacheMap:

public class NoopCacheMap<K, V> extends DefaultCacheMap<K, V> {
  @Override
  public boolean containsKey(Object key) {
    return false;
  }
}
@kirkobyte
Comment options

Could it be that I got something wrong in my MemcachedValueCache implementation or that it needs to be implemented using Try for improved invalidation?

@bbakerman
Comment options

I was doing a code inspection to work out the "disabled" ness - its possible there is more logic controlling it.

I would need to do a reproduction test case - which I didnt do - to confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.