mybatis-config.xml

<setting name="cacheEnabled" value="true" />

PersonMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.zno.smse.dao.PersonMapper" ><!--# mybatis ehcache 缓存配置 # ① 应该首先在配置文件中开启缓存功能② 以下两个 <cache> 标签二选一,第一个可以输出日志,第二个不输出日志 。<cache type="org.mybatis.caches.ehcache.LoggingEhcache" /><cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --><cache type="org.mybatis.caches.ehcache.LoggingEhcache" /><!--     省略代码 -->
</mapper>

所处位置

<!ELEMENT mapper (cache-ref | cache | resultMap* | parameterMap* | sql* | insert* | update* | delete* | select* )+>

PersonMapper.xml 中禁用单个sql语句的缓存

useCache="false"

依赖

        <dependency><groupId>org.mybatis.caches</groupId><artifactId>mybatis-ehcache</artifactId><version>1.0.2</version></dependency>

日志

初始化

-------------------------------------------------------------------
GMS: address=pc012-44159, cluster=EH_CACHE, physical address=172.16.162.238:14872
-------------------------------------------------------------------
2829 [localhost-startStop-1] INFO  n.s.e.d.j.JGroupsCacheManagerPeerProvider - JGroups Replication started for 'EH_CACHE'. JChannel: local_addr=pc012-44159
cluster_name=EH_CACHE
my_view=[pc012-44159|0] [pc012-44159]
connected=true
closed=false
discard_own_messages=true
state_transfer_supported=true
props=UDP(bind_addr=/172.16.162.238;oob_thread_pool_keep_alive_time=5000;timer_keep_alive_time=3000;external_port=0;oob_thread_pool_enabled=true;max_bundle_size=64000;diagnostics_ttl=8;receive_on_all_interfaces=false;mcast_port=45588;thread_pool_min_threads=2;thread_pool_keep_alive_time=5000;thread_pool_max_threads=8;enable_diagnostics=true;ucast_send_buf_size=640000;ip_ttl=8;oob_thread_pool_queue_max_size=100;enable_bundling=true;thread_pool_queue_enabled=true;timer_rejection_policy=run;diagnostics_port=7500;oob_thread_pool_max_threads=8;wheel_size=200;disable_loopback=false;logical_addr_cache_max_size=500;ip_mcast=true;tick_time=50;logical_addr_cache_expiration=120000;thread_pool_rejection_policy=discard;oob_thread_pool_min_threads=1;port_range=50;stats=true;mcast_send_buf_size=640000;id=21;mcast_recv_buf_size=25000000;diagnostics_addr=/224.0.75.75;bind_port=0;tos=8;oob_thread_pool_rejection_policy=Run;loopback=true;oob_thread_pool_queue_enabled=false;name=UDP;enable_unicast_bundling=false;thread_pool_enabled=true;thread_naming_pattern=cl;ucast_recv_buf_size=20000000;timer_max_threads=10;timer_queue_max_size=500;discard_incompatible_packets=true;ergonomics=true;bundler_capacity=200000;max_bundle_timeout=30;mcast_group_addr=/228.8.8.8;bind_interface_str=;timer_min_threads=4;log_discard_msgs=true;thread_pool_queue_max_size=10000;bundler_type=new;timer_type=new)
:PING(id=6;return_entire_cache=false;num_initial_members=20;break_on_coord_rsp=true;stagger_timeout=0;stats=true;name=PING;ergonomics=true;timeout=2000;num_initial_srv_members=0)
:MERGE2(id=0;stats=true;merge_fast=true;name=MERGE2;inconsistent_view_threshold=1;min_interval=10000;ergonomics=true;merge_fast_delay=1000;max_interval=30000)
:FD_SOCK(bind_addr=/172.16.162.238;external_port=0;port_range=50;stats=true;suspect_msg_interval=5000;client_bind_port=0;ergonomics=true;num_tries=3;id=3;get_cache_timeout=1000;sock_conn_timeout=1000;bind_interface_str=;name=FD_SOCK;keep_alive=true;start_port=0)
:FD_ALL(id=29;interval=3000;stats=true;name=FD_ALL;ergonomics=true;msg_counts_as_heartbeat=false;timeout=10000;timeout_check_interval=2000)
:VERIFY_SUSPECT(id=13;bind_addr=/172.16.162.238;bind_interface_str=;stats=true;name=VERIFY_SUSPECT;num_msgs=1;ergonomics=true;use_icmp=false;timeout=1500)
:BARRIER(id=0;max_close_time=60000;stats=true;name=BARRIER;ergonomics=true)
:pbcast.NAKACK2(use_mcast_xmit_req=false;use_mcast_xmit=false;max_msg_batch_size=500;xmit_from_random_member=false;stats=true;xmit_table_max_compaction_time=30000;log_not_found_msgs=true;ergonomics=true;discard_delivered_msgs=true;print_stability_history_on_failed_xmit=false;id=57;max_rebroadcast_timeout=2000;xmit_table_msgs_per_row=2000;xmit_table_num_rows=100;name=NAKACK2;log_discard_msgs=true;xmit_table_resize_factor=1.2;xmit_interval=1000)
:UNICAST(max_retransmit_time=60000;max_msg_batch_size=500;xmit_table_max_compaction_time=60000;stats=true;segment_capacity=1000;ergonomics=true;id=12;conn_expiry_timeout=60000;xmit_table_msgs_per_row=2000;xmit_table_num_rows=100;name=UNICAST;timeout=400,800,1600,3200;xmit_table_resize_factor=1.2;xmit_interval=2000)
:pbcast.STABLE(id=16;desired_avg_gossip=50000;max_bytes=4000000;stats=true;cap=0.1;name=STABLE;ergonomics=true;stability_delay=1000)
:pbcast.GMS(print_local_addr=true;stats=true;max_bundling_time=50;log_collect_msgs=true;resume_task_timeout=20000;log_view_warnings=true;num_prev_views=20;ergonomics=true;use_flush_if_present=true;print_physical_addrs=true;merge_timeout=5000;id=14;num_prev_mbrs=50;leave_timeout=1000;view_bundling=true;name=GMS;join_timeout=3000;handle_concurrent_startup=true;view_ack_collection_timeout=2000;max_join_attempts=0)
:UFC(id=45;max_block_time=5000;max_credits=2000000;stats=true;ignore_synchronous_response=true;min_credits=800000;name=UFC;min_threshold=0.4;ergonomics=true)
:MFC(id=44;max_block_time=5000;max_credits=2000000;stats=true;ignore_synchronous_response=true;min_credits=800000;name=MFC;min_threshold=0.4;ergonomics=true)
:FRAG2(id=5;frag_size=60000;stats=true;name=FRAG2;ergonomics=true)
:RSVP(id=55;stats=true;name=RSVP;resend_interval=2000;throw_exception_on_timeout=true;ergonomics=true;ack_on_delivery=true;timeout=10000)
:pbcast.STATE_TRANSFER(id=17;stats=true;name=STATE_TRANSFER;ergonomics=true)

首次时缓存

50125 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
50141 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f689a9] was not registered for synchronization because synchronization is not active
50250 [http-bio-8080-exec-6] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.0
50282 [http-bio-8080-exec-6] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [29424556, URL=jdbc:oracle:thin:@//172.16.50.67:1521/orcl, UserName=E_CHANNEL, Oracle JDBC driver] will not be managed by Spring
50282 [http-bio-8080-exec-6] DEBUG c.z.s.d.PersonMapper.countByExample - ooo Using Connection [29424556, URL=jdbc:oracle:thin:@//172.16.50.67:1521/orcl, UserName=E_CHANNEL, Oracle JDBC driver]
50297 [http-bio-8080-exec-6] DEBUG c.z.s.d.PersonMapper.countByExample - ==>  Preparing: select count(*) from PERSON
50454 [http-bio-8080-exec-6] DEBUG c.z.s.d.PersonMapper.countByExample - ==> Parameters:
50547 [http-bio-8080-exec-6] DEBUG n.s.e.d.jgroups.JGroupsCachePeer - Created asynchronous message queue for 1000ms period
50547 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f689a9]
50547 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
50547 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17c4e59] was not registered for synchronization because synchronization is not active
50547 [http-bio-8080-exec-6] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.0
50579 [http-bio-8080-exec-6] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [33276711, URL=jdbc:oracle:thin:@//172.16.50.67:1521/orcl, UserName=E_CHANNEL, Oracle JDBC driver] will not be managed by Spring
50579 [http-bio-8080-exec-6] DEBUG c.z.s.d.P.selectByExample - ooo Using Connection [33276711, URL=jdbc:oracle:thin:@//172.16.50.67:1521/orcl, UserName=E_CHANNEL, Oracle JDBC driver]
50579 [http-bio-8080-exec-6] DEBUG c.z.s.d.P.selectByExample - ==>  Preparing: select * from ( select row_.*, rownum rownum_ from ( select ID, NAME, AGE, BIRTHDAY, TYPE, SEX from PERSON ) row_ ) where rownum_ > 0 and rownum_ <= 10
50579 [http-bio-8080-exec-6] DEBUG c.z.s.d.P.selectByExample - ==> Parameters:
50625 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17c4e59]
51547 [EH_CACHE Async Replication Thread] DEBUG n.s.e.d.jgroups.JGroupsCachePeer - Sending 2 JGroupEventMessages from the asynchronous queue. 

命中缓存

59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f58af5] was not registered for synchronization because synchronization is not active
59829 [http-bio-8080-exec-10] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.3333333333333333
59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f58af5]
59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f12767] was not registered for synchronization because synchronization is not active
59829 [http-bio-8080-exec-10] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.5
59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f12767]

当执行更新操作时

361860 [http-bio-8080-exec-7] DEBUG n.s.e.d.j.JGroupsCacheReplicator - Remove all elements called on cn.zno.smse.dao.PersonMapper 

转载于:https://www.cnblogs.com/zno2/p/4858397.html

三)mybatis 二级缓存,整合ehcache相关推荐

  1. 【MyBatis框架】查询缓存-二级缓存-整合ehcache

    mybatis整合ehcache ehcache是一个分布式缓存框架. 1.分布缓存 我们系统为了提高系统并发,性能.一般对系统进行分布式部署(集群部署方式) 如图 不使用分布缓存,缓存的数据在各各服 ...

  2. Mybatis一级缓存、整合第三方缓存ehcache、Mybatis二级缓存

    8. 缓存 8.1 一级缓存 在对数据库的一次会话中,我们有可能会反复地执行完全相同的查询语句,如果不采取一些措施的话,每一次查询都会查询一次数据库,而我们在极短的时间内做了完全相同的查询,那么它们的 ...

  3. SpringBoot整合Redis配置MyBatis二级缓存

    目录 写在前面 源码获取 一.MyBatis缓存机制 1.1.一级缓存 1.2.二级缓存 二.集成Redis 2.1.安装Redis 2.2.项目引入Redis 2.2.1.Maven依赖 2.2.2 ...

  4. MyBatis缓存和二级缓存整合Redis

    MyBatis缓存和二级缓存整合Redis ⼀级缓存 缓存验证 在⼀个sqlSession中,对user表根据username进⾏两次查询,查看他们发出sql语句的情况 同样是对user表进⾏两次查询 ...

  5. 关于Spring Boot + Mybatis + Redis二级缓存整合详解

    二级缓存是多个SqlSession共享的,其作用域是mapper的同一个namespace,不同的sqlSession两次执行相同namespace下的sql语句且向sql中传递参数也相同即最终执行相 ...

  6. Mybatis二级缓存原理

    记录是一种精神,是加深理解最好的方式之一. 最近看了下Mybatis的源码,分析了二级缓存的实现方式,在这里把他记下来.虽然这不复杂,对这方面的博客也有很多,写的也很好.但我坚信看懂了是其一,能够教别 ...

  7. Mybatis 一级缓存,Mybatis 二级缓存,Mybatis 缓存失效

    Mybatis 一级缓存,Mybatis 二级缓存,Mybatis 缓存失效 ================================ ©Copyright 蕃薯耀 2021-06-24 ht ...

  8. Mybatis高级应用 整合Ehcache

    EhCache 是一个纯Java的进程内缓存框架,是一种被广泛使用的开源Java分布式的缓存框架,具有快速.精干等特点,是Hibernate中默认的缓存提供者.不使用分布缓存,缓存的数据就会在各个服务 ...

  9. 深入了解MyBatis二级缓存

    深入了解MyBatis二级缓存 一.创建Cache的完整过程 我们从SqlSessionFactoryBuilder解析mybatis-config.xml配置文件开始: Reader reader ...

  10. Mybatis 二级缓存简单示例

    简介 简单接收Mybatis中二级缓存的使用示例 概览 主要部分如下: 引入Maven依赖 SpringBoot配置文件配置.建库与初始化SQL语句 实体类与Mapper编写 测试 Maven依赖 完 ...

最新文章

  1. Robot framework+python安装使用图解版
  2. 网管日志-06.08.18
  3. 移动端通过ajax上传图片(文件)并在前台展示——通过H5的FormData对象
  4. pythonqt库_Python QT组件库qtwidgets的使用
  5. maven中去掉单元测试的配置
  6. step2 . day1 Linux和C语言的高级应用
  7. DBGrid内使用CheckBox功能
  8. Activity之launchMode:singleTop,singleTask与singleInstance
  9. 58年前,这3个人在“撕逼”中拿下诺贝尔奖!一起研究DNA的女科学家却痛苦去世.........
  10. 深度学习中的正则化技术详解
  11. 双刃剃须刀行业调研报告 - 市场现状分析与发展前景预测
  12. 路径规划——RRT算法实现
  13. stl格式导入matlab,机器人模型导入MATLAB(三):导入MATLAB URDF/stl 格式
  14. Firefox浏览器修改背景颜色为豆沙绿
  15. linux中ftp禁止匿名,linux下禁止root和匿名用户登录ftp
  16. 2013-2014年度总结
  17. 色环电阻的电阻值大小的确定
  18. Python编写微信打飞机小游戏(三)
  19. EasyUI DataGrid 隐藏其中一列
  20. 如何优化网站关键词?

热门文章

  1. 链接在HTML的英文,英文:A链接标记ie下会自动补全href_HTML/Xhtml_网页制作
  2. python同步oracle_Python cx_Oracle 7引入苏打文档存储
  3. 方法的绑定机制-静态绑定和动态绑定
  4. 栈出现的异常和设置栈的大小-Xss
  5. 超级好看的14 款 Chrome 官方主题,有你喜欢的吗?
  6. SQLServer数据库文件组相关知识笔记
  7. 后端:Spring IOC 知识点总结,写得太好了!
  8. 跨网段远程调试vs_如何提高后台服务应用问题的排查效率?日志 VS 远程调试
  9. Mysql bat脚本编写_第一次编写bat脚本
  10. 计算机网络技术课程代码02141模拟试题,02141计算机网络技术201510真题及答案