Cache the Java code generation templates

This change results in an ~18% improvement in unit test execution speed.