Using the Grails Cache Plugin on Normal Spring Service Bean

500 Views Asked by At

i have some standard Spring @Service classes in a separate jar lib that use the standard @Cacheable Spring annotation, in a Spring boot project i declare the dependency, configure a CacheManager and just works!

i try to do the same in a Grails 3.1 project but with no luck! i discover that https://github.com/grails-plugins/grails-cache require to use its 'proprietary' @Cacheable annotation:

http://grails-plugins.github.io/grails-cache/3.0.x/api/grails/plugin/cache/Cacheable.html

As workaround i FORKED some Service just to use the Grails @Cacheable and it's working but i'd like to have a single @Service that works under grails or not!


I have misconfigured something, it doesn't behave the same way, but i can't figure out what is it!

i'd like to share this jar lib between spring only & grails projects, but so far i can't make caching work, unless i forked the service calsses under grails-app/services directory & used 'proprietary' @Cacheable annotation;

i try to remove the plugin and configure the bean and the cache in: /GPsGrails3/grails-app/init/gpsgrails3/Application.groovy with the org.springframework.context.annotation.Bean annotation:

@Primary
@Bean
public ConcurrentMapCacheManager concurrentMapCacheManager() {
    return new ConcurrentMapCacheManager();
}

@Bean
public SignatureService signatureService() {
    SignatureService _signatureService = new SignatureService();
    return _signatureService;
}

i put signatureService under grails-app/services directory: /GPsGrails3/grails-app/services/it/finmatica/ifw/impl/SignatureService.groovy

Maybe i have to configure my beans in: /GPsGrails3/grails-app/conf/spring/resources.groovy ?

i have to use the version 4 of the plugin? compile "org.grails.plugins:cache:4.+"

1

There are 1 best solutions below

11
On

I am not sure what the question is but you don't have to use the Grails @Cacheable annotation. If you want to use the Spring one in a Grails app, you can, and it will behave in the same way that it would if you weren't using Grails. You don't even need the plugin in order to do that.