Created
April 5, 2018 12:18
-
-
Save mmimica/058132ee7dfc81842320908591eba575 to your computer and use it in GitHub Desktop.
cached data provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface DataProvider<I, R> { | |
T calculate(I input); | |
} | |
@RequiredArgsConstructor | |
public class DataProviderCached<I, R> implements DataProvider<I, R> { | |
private final DataProvider delegate; | |
private final Map<I, R> cache = new ConcurrentHashMap<>(); | |
@Override | |
public R calculate(I input) { | |
return cache.computeIfAbsent(input, delegate::calculate); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment