1 Star 2 Fork 0

github/redisson

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Redis based MyBatis Cache implementation

Implements MyBatis Cache based on Redis.

Compatible with MyBatis 3.0.0+

Redisson provides various MyBatis Cache implementations including those with features below:

local cache - so called near cache, which is useful for use cases when MyBatis Cache used mostly for read operations and/or network roundtrips are undesirable. It caches Map entries on Redisson side and executes read operations up to 45x faster in comparison with common implementation. All local caches with the same name connected to the same pub/sub channel which is used for messaging between them. In particular to send entity update or entity invalidate event.

data partitioning - allows to scale available memory, read/write operations and entry eviction process for individual MyBatis Cache instance in Redis cluster.

Below is the list of all available implementations with local cache and/or data partitioning support:

Class name Local cache Data
partitioning
Ultra-fast read/write
RedissonCache
open-source version
RedissonCache
Redisson PRO version
✔️
RedissonLocalCachedCache
available only in Redisson PRO
✔️ ✔️
RedissonClusteredCache
available only in Redisson PRO
✔️ ✔️
RedissonClusteredLocalCachedCache
available only in Redisson PRO
✔️ ✔️ ✔️

MyBatis Cache Usage

1. Add redisson-mybatis dependency into your project:

Maven

     <dependency>
         <groupId>org.redisson</groupId>
         <artifactId>redisson-mybatis</artifactId>
         <version>3.17.7</version>
     </dependency>

Gradle

     compile 'org.redisson:redisson-mybatis:3.17.7'

2. Specify MyBatis cache settings

Redisson allows to define follow settings per Cache instance:

timeToLive - defines time to live per cache entry

maxIdleTime - defines max idle time per cache entry

maxSize - defines max size of entries amount stored in Redis

localCacheProvider - cache provider used as local cache store. REDISSON and CAFFEINE providers are available. Default value: REDISSON

localCacheEvictionPolicy - local cache eviction policy. LFU, LRU, SOFT, WEAK and NONE eviction policies are available.

localCacheSize - local cache size. If size is 0 then local cache is unbounded.

localCacheTimeToLive - time to live in milliseconds for each map entry in local cache. If value equals to 0 then timeout is not applied.

localCacheMaxIdleTime - max idle time in milliseconds for each map entry in local cache. If value equals to 0 then timeout is not applied.

localCacheSyncStrategy - local cache sync strategy. INVALIDATE, UPDATE and NONE eviction policies are available.

redissonConfig - defines path to redisson config in YAML format

Examples:

<cache type="org.redisson.mybatis.RedissonCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<!-- or -->
<cache type="org.redisson.mybatis.RedissonLocalCachedCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>

  <property name="localCacheEvictionPolicy" value="LRU"/>
  <property name="localCacheSize" value="1000"/>
  <property name="localCacheTimeToLive" value="2000000"/>
  <property name="localCacheMaxIdleTime" value="1000000"/>
  <property name="localCacheSyncStrategy" value="INVALIDATE"/>
     
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<!-- or -->
<cache type="org.redisson.mybatis.RedissonClusteredCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>

<!-- or -->
<cache type="org.redisson.mybatis.RedissonClusteredLocalCachedCache">
  <property name="timeToLive" value="200000"/>
  <property name="maxIdleTime" value="100000"/>
  <property name="maxSize" value="100000"/>
     
  <property name="localCacheEvictionPolicy" value="LRU"/>
  <property name="localCacheSize" value="1000"/>
  <property name="localCacheTimeToLive" value="2000000"/>
  <property name="localCacheMaxIdleTime" value="1000000"/>
  <property name="localCacheSyncStrategy" value="INVALIDATE"/>
     
  <property name="redissonConfig" value="redisson.yaml"/>
</cache>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yexw-github/redisson.git
git@gitee.com:yexw-github/redisson.git
yexw-github
redisson
redisson
master

搜索帮助