All Projects → debop → Hibernate Redis

debop / Hibernate Redis

Licence: apache-2.0
hibernate 2nd level cache privder using redis

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Hibernate Redis

Redisson
Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Stars: ✭ 17,972 (+5109.28%)
Mutual labels:  hibernate, redis, cache
Springbootunity
rabbitmq、redis、scheduled、socket、mongodb、Swagger2、spring data jpa、Thymeleaf、freemarker etc. (muti module spring boot project) (with spring boot framework,different bussiness scence with different technology。)
Stars: ✭ 845 (+144.93%)
Mutual labels:  hibernate, redis
Hazelcast Hibernate
A distributed second-level cache for Hibernate
Stars: ✭ 24 (-93.04%)
Mutual labels:  hibernate, cache
Superboot
随着技术日新月异,新技术新平台不断出现,对现如今的开发人员来说选择快速高效的框架进行项目开发,既能提高产出,又能节约时间。本框架无需开发即可实现服务注册、服务发现、负载均衡、服务网关、配置中心、API管理、分布式事务、支撑平台、集成框架、数据传输加密等功能,是学习SpringCloud整体业务模式的完整示例,并且可以直接用于生产环境
Stars: ✭ 341 (-1.16%)
Mutual labels:  hibernate, redis
Pottery
Redis for humans. 🌎🌍🌏
Stars: ✭ 204 (-40.87%)
Mutual labels:  redis, cache
Springboot Examples
spring boot 实践系列
Stars: ✭ 216 (-37.39%)
Mutual labels:  redis, cache
Jetcache
JetCache is a Java cache framework.
Stars: ✭ 3,167 (+817.97%)
Mutual labels:  redis, cache
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+529.28%)
Mutual labels:  redis, cache
Senparc.co2net
支持 .NET Framework & .NET Core 的公共基础扩展库
Stars: ✭ 289 (-16.23%)
Mutual labels:  redis, cache
Hibernate Ogm
Hibernate OGM - Domain model persistence for NoSQL datastores
Stars: ✭ 299 (-13.33%)
Mutual labels:  hibernate, redis
Cachingframework.redis
Distributed caching based on StackExchange.Redis and Redis. Includes support for tagging and is cluster-compatible.
Stars: ✭ 209 (-39.42%)
Mutual labels:  redis, cache
Koa Redis
Redis storage for Koa session middleware/cache with Sentinel and Cluster support
Stars: ✭ 324 (-6.09%)
Mutual labels:  redis, cache
Endb
Key-value storage for multiple databases. Supports MongoDB, MySQL, Postgres, Redis, and SQLite.
Stars: ✭ 208 (-39.71%)
Mutual labels:  redis, cache
Javaquarkbbs
基于Spring Boot实现的一个简易的Java社区
Stars: ✭ 755 (+118.84%)
Mutual labels:  hibernate, redis
Redis Cache
A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Credis, HHVM, replication and clustering.
Stars: ✭ 205 (-40.58%)
Mutual labels:  redis, cache
Spring Rest Ecommerce
Java Spring Boot - Ecommerce REST API
Stars: ✭ 164 (-52.46%)
Mutual labels:  hibernate, redis
Nginx Helper
Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
Stars: ✭ 170 (-50.72%)
Mutual labels:  redis, cache
Ansible Role Redis
Ansible Role - Redis
Stars: ✭ 176 (-48.99%)
Mutual labels:  redis, cache
Scrapbook
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
Stars: ✭ 279 (-19.13%)
Mutual labels:  redis, cache
Cache
Cache library
Stars: ✭ 310 (-10.14%)
Mutual labels:  redis, cache

hibernate-redis

Maven Central Build Status

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)

Note

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

Setup

Maven Repository

add dependency

<dependency>
    <groupId>com.github.debop</groupId>
    <artifactId>hibernate-redis</artifactId>
    <version>2.3.2</version>
</dependency>

Optional dependencies. Redisson support various codec (serializer, compression). you can choose other codec. see Redisson Help.

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson</artifactId>
    <version>${redisson.version}</version>
</dependency>
<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>${fst.version}</version>
</dependency>
<dependency>
    <groupId>org.xerial.snappy</groupId>
    <artifactId>snappy-java</artifactId>
    <version>${snappy-java.version}</version>
</dependency>
Setup hibernate configuration

Setup hibernate configuration (Note package name for hibernate 4 / hibernate 5 / hibernate52)

// Secondary Cache
props.put(Environment.USE_SECOND_LEVEL_CACHE, true);
props.put(Environment.USE_QUERY_CACHE, true);
props.put(Environment.CACHE_REGION_FACTORY, org.hibernate.cache.redis.hibernate52.SingletonRedisRegionFactory.class.getName());
props.put(Environment.CACHE_REGION_PREFIX, "hibernate");

// Optional setting for second level cache statistics
props.setProperty(Environment.GENERATE_STATISTICS, "true");
props.setProperty(Environment.USE_STRUCTURED_CACHE, "true");

// Hibernate 4
props.setProperty(Environment.TRANSACTION_STRATEGY, JdbcTransactionFactory.class.getName());

// Configuration for Redis that used by hibernate
props.put(Environment.CACHE_PROVIDER_CONFIG, "hibernate-redis.properties");

also same configuration for using Spring Framework or Spring Data JPA

Redis settings for hibernate-redis

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=1200

sample for Redisson configuration (see more samples )

# redisson configuration for redis servers
# see : https://github.com/mrniko/redisson/wiki/2.-Configuration

singleServerConfig:
  idleConnectionTimeout: 10000
  pingTimeout: 1000
  connectTimeout: 1000
  timeout: 1000
  retryAttempts: 1
  retryInterval: 1000
  reconnectionTimeout: 3000
  failedAttempts: 1
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  address: "redis://127.0.0.1:6379"
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 25
  connectionMinimumIdleSize: 5
  connectionPoolSize: 100
  database: 0
  dnsMonitoring: false
  dnsMonitoringInterval: 5000
threads: 0
# Codec
codec: !<org.redisson.codec.SnappyCodec> {}
useLinuxNativeEpoll: false
eventLoopGroup: null

Hibernate configuration via Spring Application property files

In Spring applications, the hibernate- and hibernate-redis configuration represented above can be configured within Spring application property files like below.

spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.redis.hibernate52.SingletonRedisRegionFactory
spring.jpa.properties.hibernate.cache.region_prefix=hibernate

spring.jpa.properties.hibernate.cache.use_structured_entries=true
spring.jpa.properties.hibernate.generate_statistics=true

spring.jpa.properties.redisson-config=classpath:conf/redisson.yaml

spring.jpa.properties.redis.expiryInSeconds.default=120
spring.jpa.properties.redis.expiryInSeconds.hibernate.common=0
spring.jpa.properties.redis.expiryInSeconds.hibernate.account=1200

Setup hibernate entity to use cache

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;
}

How to monitor hibernate-cache is running

run "redis-cli monitor" command in terminal. you can see putting cached items, retrieving cached items.

Sample code

see hibernate-examples module

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].