Skip to content

Instantly share code, notes, and snippets.

@kijanowski
Created September 30, 2019 16:05
Show Gist options
  • Select an option

  • Save kijanowski/8a00a2f927601c08361c5d396fa30bcb to your computer and use it in GitHub Desktop.

Select an option

Save kijanowski/8a00a2f927601c08361c5d396fa30bcb to your computer and use it in GitHub Desktop.
@Bean
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Profile("global")
public DataLoaderRegistry globalDataLoaderRegistry(
@Value("${cache.maxCacheSize}") long maxCacheSize,
@Value("${cache.expiryInSeconds}") long expiryInSeconds
) {
DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
CacheMap customCache = new CustomGuavaBasedCache(maxCacheSize, expiryInSeconds);
DataLoaderOptions options = DataLoaderOptions.newOptions().setCacheMap(customCache);
DataLoader<String, CountryTO> countryLoader = DataLoader.newDataLoader(graphQLDataFetchers.countryBatchLoader(), options);
dataLoaderRegistry.register("countries", countryLoader);
return dataLoaderRegistry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment