Using a cache
A cache can be used at two levels in JHipster:
- With the Spring Cache abstraction, which is a specific question when your application is generated, and which uses the Spring Boot
@EnableCaching
annotation. This needs to be tuned according to your specific business needs, and works at a higher level than the Hibernate 2nd-level cache. - As an Hibernate 2nd-level cache, a caching solution can give a huge performance boost to your application, and this is what people usually do with JHipster. Please note that this option is only available for SQL databases, and if you have selected to use Spring Cache.
Spring Cache and the Hibernate 2nd-level cache will use the same caching solution, but do not work at the same level: we do not recommend to use both for the same objects, as this will make cache invalidation issues even more complex. Instead, we recommend you use:
- Spring Cache for higher-level or aggregate objects, like you typically have with DTOs
- The Hibernate 2nd-level cache for entities mapped to the database, in order to reduce the number of SQL requests
JHipster supports the following cache implementations:
- Ehcache,
- Caffeine,
- Hazelcast,
- Infinispan,
- Memcached,
- Redis.
They are all detailed below.