groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francesco Chicchiriccò"<ilgro...@apache.org>
Subject Re: Cache parsed classes
Date Wed, 04 Oct 2017 07:21:28 GMT
On 2017-10-03 18:38, Jochen Theodorou <blackdrag@gmx.org> wrote: 
> 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.

Thanks for your answer.

No, there is no session that can be involved here.

The classBody string is expected to vary frequently during the development phase, and rarely
when the system is in production.

Managing the cache with an in-memory Map is fine to me, I just want to avoid duplicating any
existing mechanism already implemented in Groovy. 

Regards.

Mime
View raw message