Reputation: 1236
I want EHCache in production, but not in development as I tend to fiddle with database records in development.
The only thing I came across after searching is this JVM option to disable cache completely -Dnet.sf.ehcache.disabled=true
, but somehow this does not appear to be the ideal solution.
Best would be to have an option in application-dev.yml. I tinkered with timeToLiveSeconds and kept it low (1), but it did not seem to have any effect.
I tried to add an api in my REST service like this, but it did not seem to have any effect either:
/**
* GET /clearCache -> Clear Cache
*/
@RequestMapping(value = "/clearCache",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<String> clearCache() {
CacheManager.getInstance().clearAll();
return new ResponseEntity<String>(HttpStatus.OK);
}
Also, a corollary to this same question, I put a debug breakpoint in CacheConfiguration.java here, but it never seems to get hit.
@PreDestroy
public void destroy() {
Any help is highly appreciated!
Here is my full log on startup with fast boot:
[INFO] mypackage.Application - Starting Application on Lenovo-PC with PID 7408 (D:\projects\app\target\classes started by lenovo in D:\projects\app)
[DEBUG] mypackage.Application - Running with Spring Boot v1.2.4.RELEASE, Spring v4.1.6.RELEASE
[DEBUG] org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
[DEBUG] mypackage.config.DatabaseConfiguration - Configuring Datasource
[WARN] org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for cache named [mypackage.Org]; using defaults.
[WARN] org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for cache named [mypackage.Workflow]; using defaults.
[WARN] org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for cache named [mypackage.Department]; using defaults.
...
...
...
[DEBUG] mypackage.config.MailConfiguration - Configuring mail server
[INFO] mypackage.Application - Running with Spring profile(s) : [dev, fast]
Upvotes: 3
Views: 5365
Reputation: 16294
If you look at the CacheConfiguration class, you'll see:
@Profile("!" + Constants.SPRING_PROFILE_FAST)
public class CacheConfiguration {
So if you use fast profile, caching is disabled, so either you use this profile or you change annotation to enable caching only in prod profile.
@Profile(Constants.SPRING_PROFILE_PRODUCTION)
public class CacheConfiguration {
You're right, the ehcache code where the WARN log is issued creates a cache anyway and it does it for your 3 entities: Org, Workflow and Department.
if ( cache == null ) {
LOG.unableToFindEhCacheConfiguration( name );
manager.addCache( name );
cache = manager.getEhcache( name );
LOG.debug( "started EHCache region: " + name );
}
I'm not sure the cache is used for entities as our configuration is not run but anyway even the warning is not satisfying, there's probably something missing in our configuration to avoid it.
Could you please open an issue ?
Upvotes: 2