groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <>
Subject Re: Cache parsed classes
Date Tue, 03 Oct 2017 16:38:05 GMT
On 03.10.2017 10:52, Francesco Chicchiriccò wrote:
> When one of available implementations is requested, we do something as follows:
>      private static final GroovyClassLoader GROOVY_CLASSLOADER = new GroovyClassLoader();
>      @SuppressWarnings("unchecked")
>      private static <T> T buildGroovy(final String classBody) throws InstantiationException,
IllegalAccessException {
>          Class<?> clazz = GROOVY_CLASSLOADER.parseClass(classBody);
>          return (T) ApplicationContextProvider.getBeanFactory().
>                  createBean(clazz, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
>      }
> I am happy to say that this works just fine.
> Now I was wondering what is the best approach to cache such information, to avoid Groovy
parsing the class source text at every execution request.

If classBody across requests for the live time of the session, then you 
can save the bean in the session scope. If there is no real session, 
then I need to know how the different classbody differ. And that aspect 
would be for me a key for a map, that has the clazz as value.

bye Jochen

View raw message