16. GRAILS SPRING CACHE
• grails install-plugin springcache
• Add @Cacheable (and or @CacheFlush) annotation to
services / controllers
@Cacheable('somecachename')
def slow(String name) {
log.info "resolving $name"
Thread.sleep(2000)
return "took a long time to resolve ${name}"
}
17. GPARS
• BuildConfig.groovy:
runtime 'org.codehaus.gpars:gpars:0.10'
runtime 'org.coconut.forkjoin.jsr166y:jsr166y:070108'
• http://www.gpars.org/guide/index.html
• Note:hibernate session is not available on GPars threads; you
need to get one yourself (use DomainClass.withTransaction)
• Data Parallelism
• Map-Reduce, Fork-Join, and many more...
18. GPARS
void resolve(scoreDocs){
scoreDocs.each {scoreDoc ->
//do something in single thread
}
}
void resolveWithPool(scoreDocs){
GParsPool.withPool {
scoreDocs.eachParallel {scoreDoc ->
//do something in parallel
}
}
}