1 package org.onap.vid.aai.util;
4 import java.util.function.Function;
5 import java.util.stream.Collectors;
6 import java.util.stream.Stream;
8 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
10 public interface CacheProvider {
11 String KEY_DELIMITER = "!@#'";
13 Returns the cache associated with given name; creates one if wasn't any
15 <K, V> Cache<K, V> aaiClientCacheFor(String name, Function<K, V> loader);
18 reset cache if exist. Otherwise do nothing
20 void resetCache(String name);
22 interface Cache<K, V> {
26 static String compileKey(List<String> args) {
27 return compileKey(args.toArray(new String[0]));
30 static String compileKey(String... args) {
31 return Stream.of(args).map(arg->defaultIfNull(arg, "")).collect( Collectors.joining( KEY_DELIMITER ) );
34 static String[] decompileKey(String key) {
35 return key.split(KEY_DELIMITER);