hibernate 2nd level cache privder using redis
hibernate (4.x, 5.1.x, 5.2.x) 2nd level cache provider using redis server 3.x. with Redisson 2.3.x
Reduce cache size by Redisson SnappyCodec (see snappy-java, Fast-Serialization)
From 2.2.1 onwards Hibernate region naming (hibernate.cache.region_prefix) has been simplified to "hibernate".
hibernate-core 5.2.x based on Java 8, use hibernate-redis 2.2.0 or higher
Region factory for hibernate 5.2.x is hibernate.redis.cache.hibernate52.SingletonRedisRegionFactory
add dependency
com.github.debop
hibernate-redis
2.3.2
Optional dependencies. Redisson support various codec (serializer, compression). you can choose other codec. see Redisson Help.
org.redisson
redisson
${redisson.version}
de.ruedigermoeller
fst
${fst.version}
org.xerial.snappy
snappy-java
${snappy-java.version}
Setup hibernate configuration (Note package name for hibernate 4 / hibernate 5 / hibernate52)
…also same configuration for using Spring Framework or Spring Data JPA
sample for hibernate-redis.properties
##########################################################
#
# properities for hibernate-redis
#
##########################################################
# Redisson configuration file
redisson-config=conf/redisson.yaml
# Cache Expiry settings
# 'hibernate' is second cache prefix
# 'common', 'account' is actual region name
redis.expiryInSeconds.default=120
redis.expiryInSeconds.hibernate.common=0
redis.expiryInSeconds.hibernate.account=1200sample for Redisson configuration (see more samples )
…In Spring applications, the hibernate- and hibernate-redis configuration represented above can be configured within Spring application property files like below.
…add @org.hibernate.annotations.Cache annotation to Entity class like this
@Entity
@Cache(region="common", usage = CacheConcurrencyStrategy.READ_WRITE) // or @Cacheable(true) for JPA
@Getter
@Setter
public class Item implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String description;
private static final long serialVersionUID = -281066218676472922L;
}run "redis-cli monitor" command in terminal. you can see putting cached items, retrieving cached items.
see hibernate-examples module
No open issues yet, or sync has not completed.