Reputation: 3907
In bootstrap, I would like to:
Is there a plugin to help me do this?
Upvotes: 0
Views: 143
Reputation: 20699
I'm using compile 'com.google.guava:guava:18.0-rc2'
see wiki, which provides also auto-eviction.
Upvotes: 0
Reputation: 35961
It doesn't look like caching (i.e. temp value, ephemeral, that could be lost at any moment), it's precalculated value. Don't think cache plugin will help.
Basically you need a place to keep this value. It could be anything actually, a static
variable from a basic POJO class for example. But if we're talking about Grails I suggest to make a special Service, that will store value, have a method to get it, and probably a method to make initial calculations. Service is a singleton, shared between different artifacts, it will be easy to extend with new logic, refactor and support this code in future. And easier to understand/remember, in contrast to some magical value coming from a cache.
Like:
class SuperValueService {
def value
void refresh() {
value = ...
}
}
Init in bootstrap:
class Bootstrap {
def superValueService
def init { ->
superValueService.refresh()
}
}
and use from controller:
class MyController {
def superValueService
def action() {
render models: [superValue: superValueService.value]
}
}
Upvotes: 3