Cache#
In Igloo cache is used :
By Hibernate as second-level cache
By Spring at css generation
Each one has an independant CacheManager.
As cache provider you can use :
For Hibernate : EhCache 2.X or JCache (Caffeine)
For Spring : JCache (Caffeine)
Update caching backend#
New reference implementation for caching is caffeine
Second-level cache is configured by
hibernate.cacheproperty (none,ehcache,ehcache-singleton,jcache-caffeine)Second-level cache configuration file is configured by
hibernate.jcache.configurationLocation(expects a classpath:// url)Documentation for caffeine configuration format: ben-manes/caffeine
hibernate.ehCache.configurationLocationis used only for deprecated ehcache configurationSpring caching now uses spring-boot properties https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties.cache
Default configuration and basic-application uses caffeine both for spring and hibernate caches
Rewritten and split monitoring pages in igloo-cache module
Some cache-related javaconfigs move from basic-application to igloo
Caffeine migration#
General instructions for migration :
Hibernate#
Rewrite
Application : ConsoleConfiguration.build("console", propertyService);toConsoleConfiguration.build("console", propertyService, getResourceSettings());To keep second-level cache using EhCache : reconfigure second-level cache :
Search
hibernate.ehCache.configurationLocationIf empty, replace with
hibernate.cache=noneIf not empty, add
hibernate.cache=ehcacheif you want to keep ehcache2
Search
hibernate.ehCache.singleton=trueYou need
hibernate.cache=ehcache-singletoninstead of ehcache
Add
net.sf.ehcache:ehcacheandorg.hibernate:hibernate-ehcacheto core dependencies :<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> </dependency>
To switch second-level cache to Caffeine :
Set
hibernate.cache=jcache-caffeineSet
hibernate.jcache.configurationLocation=classpath://hibernate/hibernate-jcache-caffeine.confAdapt
hibernate-jcache-caffeine.conffromehcache-hibernate.xmlfile (you can check that correct configuration is loaded in console)Remove
hibernate.ehCache.configurationLocationpropertyRemove
ehcache-hibernate.xmlfileAdd
org.hibernate.hibernate-jcacheas core dependency :<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-jcache</artifactId> </dependency>
Remove
net.sf.ehcache:ehcacheandorg.hibernate:ehcache
Spring#
Switch Spring cache to Caffeine :
Add
spring.cache.type=caffeineandspring.cache.caffeine.spec=maximumSize=10, recordStatsin your configuration.propertiesDelete your
<Project>WebappCacheConfigif you have not difference with basic-application defaults. This is now done by igloo spring autoconfiguration. Delete this config @import.Delete your
cache-web-context.xmlandehcache-cache-web.xmlconfiguration. Adapt previously added maximumSize based on this file content.Add
com.github.ben-manes.caffeine:caffeineandcom.github.ben-manes.caffeine:jcacheas core dependency :<dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>jcache</artifactId> </dependency>
Add igloo-cache to webapp dependencies :
<dependency> <groupId>org.iglooproject.components</groupId> <artifactId>igloo-cache</artifactId> <version>${igloo.version}</version> </dependency>