Skip to content

Instantly share code, notes, and snippets.

@mmimica
Created April 4, 2018 15:44
Show Gist options
  • Save mmimica/2540f1af3c828f454d002ca650cb4534 to your computer and use it in GitHub Desktop.
Save mmimica/2540f1af3c828f454d002ca650cb4534 to your computer and use it in GitHub Desktop.
interview sample
@Data
class Result {
// ...
}
@Data
class Input {
// ...
}
interface DataProvider {
Result calculate(Input input);
}
@RequiredArgsConstructor
public class DataProviderCached implements DataProvider {
private final DataProvider delegate;
private final Map<Input, Result> cache = new ConcurrentHashMap<>();
@Override
public Result calculate(Input 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