org.apache.flink.shaded.guava18.com.google.common.cache.Cache Java Examples

The following examples show how to use org.apache.flink.shaded.guava18.com.google.common.cache.Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompileUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Compiles a generated code to a Class.
 * @param cl the ClassLoader used to load the class
 * @param name  the class name
 * @param code  the generated code
 * @param <T>   the class type
 * @return  the compiled class
 */
@SuppressWarnings("unchecked")
public static <T> Class<T> compile(ClassLoader cl, String name, String code) {
	try {
		Cache<ClassLoader, Class> compiledClasses = COMPILED_CACHE.get(name,
				() -> CacheBuilder.newBuilder().maximumSize(5).weakKeys().softValues().build());
		return compiledClasses.get(cl, () -> doCompile(cl, name, code));
	} catch (Exception e) {
		throw new FlinkRuntimeException(e.getMessage(), e);
	}
}