mybatis-config.xml

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

PersonMapper.xml

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

所处位置

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

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

  1. useCache="false"

依赖

  1. <dependency>
  2. <groupId>org.mybatis.caches</groupId>
  3. <artifactId>mybatis-ehcache</artifactId>
  4. <version>1.0.2</version>
  5. </dependency>

日志

初始化

  1. -------------------------------------------------------------------
  2. GMS: address=pc012-44159, cluster=EH_CACHE, physical address=172.16.162.238:14872
  3. -------------------------------------------------------------------
  4. 2829 [localhost-startStop-1] INFO n.s.e.d.j.JGroupsCacheManagerPeerProvider - JGroups Replication started for 'EH_CACHE'. JChannel: local_addr=pc012-44159
  5. cluster_name=EH_CACHE
  6. my_view=[pc012-44159|0] [pc012-44159]
  7. connected=true
  8. closed=false
  9. discard_own_messages=true
  10. state_transfer_supported=true
  11. 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)
  12. :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)
  13. :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)
  14. :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)
  15. :FD_ALL(id=29;interval=3000;stats=true;name=FD_ALL;ergonomics=true;msg_counts_as_heartbeat=false;timeout=10000;timeout_check_interval=2000)
  16. :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)
  17. :BARRIER(id=0;max_close_time=60000;stats=true;name=BARRIER;ergonomics=true)
  18. :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)
  19. :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)
  20. :pbcast.STABLE(id=16;desired_avg_gossip=50000;max_bytes=4000000;stats=true;cap=0.1;name=STABLE;ergonomics=true;stability_delay=1000)
  21. :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)
  22. :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)
  23. :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)
  24. :FRAG2(id=5;frag_size=60000;stats=true;name=FRAG2;ergonomics=true)
  25. :RSVP(id=55;stats=true;name=RSVP;resend_interval=2000;throw_exception_on_timeout=true;ergonomics=true;ack_on_delivery=true;timeout=10000)
  26. :pbcast.STATE_TRANSFER(id=17;stats=true;name=STATE_TRANSFER;ergonomics=true)

首次时缓存

  1. 50125 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
  2. 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
  3. 50250 [http-bio-8080-exec-6] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.0
  4. 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
  5. 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]
  6. 50297 [http-bio-8080-exec-6] DEBUG c.z.s.d.PersonMapper.countByExample - ==> Preparing: select count(*) from PERSON
  7. 50454 [http-bio-8080-exec-6] DEBUG c.z.s.d.PersonMapper.countByExample - ==> Parameters:
  8. 50547 [http-bio-8080-exec-6] DEBUG n.s.e.d.jgroups.JGroupsCachePeer - Created asynchronous message queue for 1000ms period
  9. 50547 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f689a9]
  10. 50547 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
  11. 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
  12. 50547 [http-bio-8080-exec-6] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.0
  13. 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
  14. 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]
  15. 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
  16. 50579 [http-bio-8080-exec-6] DEBUG c.z.s.d.P.selectByExample - ==> Parameters:
  17. 50625 [http-bio-8080-exec-6] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17c4e59]
  18. 51547 [EH_CACHE Async Replication Thread] DEBUG n.s.e.d.jgroups.JGroupsCachePeer - Sending 2 JGroupEventMessages from the asynchronous queue.

命中缓存

  1. 59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
  2. 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
  3. 59829 [http-bio-8080-exec-10] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.3333333333333333
  4. 59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f58af5]
  5. 59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
  6. 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
  7. 59829 [http-bio-8080-exec-10] DEBUG o.a.i.cache.decorators.LoggingCache - Cache Hit Ratio [cn.zno.smse.dao.PersonMapper]: 0.5
  8. 59829 [http-bio-8080-exec-10] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f12767]

当执行更新操作时

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

三)mybatis 二级缓存,整合ehcache的更多相关文章

  1. mybatis中二级缓存整合ehcache实现分布式缓存

    mybatis自带二级缓存,但是这个缓存是单服务器工作,无法实现分布式缓存.那么什么是分布式缓存呢?假设现在有两个服务器1和2,用户访问的时候访问了1服务器,查询后的缓存就会放在1服务器上,假设现在有 ...

  2. mybatis二级缓存应用及与ehcache整合

    mybaits的二级缓存是mapper范围级别,除了在SqlMapConfig.xml设置二级缓存的总开关,还要在具体的mapper.xml中开启二级缓存. 1.开启mybatis的二级缓存 在核心配 ...

  3. Springboot整合Ehcache 解决Mybatis二级缓存数据脏读 -详细

    前面有写了一篇关于这个,但是这几天又改进了一点,就单独一篇在详细说明一下 配置 application.properties ,启用Ehcache # Ehcache缓存 spring.cache.t ...

  4. MyBatis功能点一应用:二级缓存整合redis

    Mybatis提供了默认的cache实现PerpetualCache,那为什么还要整合第三方的框架redis?因为Mybatis提供的cache实现为单机版,无法实现分布式存储(即本机存储的数据,其他 ...

  5. 深入了解MyBatis二级缓存

    深入了解MyBatis二级缓存 标签: mybatis二级缓存 2015-03-30 08:57 41446人阅读 评论(13) 收藏 举报  分类: Mybatis(51)  版权声明:版权归博主所 ...

  6. MyBatis二级缓存配置

    正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 Mybatis二级缓存是SessionFactory,如果两次查询基于同一个SessionFactory,那么就从二级缓存 ...

  7. MyBatis 二级缓存全详解

    目录 MyBatis 二级缓存介绍 二级缓存开启条件 探究二级缓存 二级缓存失效的条件 第一次SqlSession 未提交 更新对二级缓存影响 探究多表操作对二级缓存的影响 二级缓存源码解析 二级缓存 ...

  8. Mybatis 二级缓存应用 (21)

    [MyBatis 二级缓存] 概述:一级缓存作用域为同一个SqlSession对象,而二级缓存用来解决一级缓存不能夸会话共享,作用范围是namespace级,可以被多个SqlSession共享(只要是 ...

  9. mybatis二级缓存

    二级缓存区域是根据mapper的namespace划分的,相同namespace的mapper查询数据放在同一个区域,如果使用mapper代理方法每个mapper的namespace都不同,此时可以理 ...

  10. 如何细粒度地控制你的MyBatis二级缓存(mybatis-enhanced-cache插件实现)

    前几天网友chanfish 给我抛出了一个问题,笼统地讲就是如何能细粒度地控制MyBatis的二级缓存问题,酝酿了几天,觉得可以写个插件来实现这个这一功能.本文就是从问题入手,一步步分析现存的MyBa ...

随机推荐

  1. & 运算

    var f:uint; var e:uint; f=uint.MAX_VALUE; e=1<<31; trace(f,e,f&e); //output:4294967295 214 ...

  2. import变量名,导入模块

    想要把不同的模块名赋值到变量,然后import进来   直接使用下面的方法是不行的: moudle="os" import moudle   会提示下面的错误: ImportErr ...

  3. 120. Triangle(Array; DP)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. Oracle数据库迁移的几种方式

    面试: 一.exp/imp逻辑备份与恢复: 二.Storage存储迁移: 将数据文件.控制文件.日志文件.spfile挂到新机器上,然后在新机器上启动数据库. 三.利用data guard迁移: 四. ...

  5. 【英宝通Unity4.0公开课学习 】(一)资源管理

    经过多次面试后发现自己对Unity3D的框架缺乏一个整体的认识. 而前面由于离职等原因总是忙于修修补补,疲于奔命,感觉相当疲惫. 还好,后来经过调整,开始淡定了起来.得特别感谢一本书哇:<高效人 ...

  6. Hamburgers

    Hamburgers http://codeforces.com/problemset/problem/371/C time limit per test 1 second memory limit ...

  7. Django的模板语言介绍

    模板语言: 1.我们先看下在命令行中渲染模板 先导入模块对象 2.渲染一个变量 <p>当前时间:{{ time }}</p> return render(request,&qu ...

  8. ROS学习笔记二(创建ROS软件包)

    catkin软件包的组成 一个软件包必须满足如下条件才能被称之为catkin软件包: 必须包含一个catkin编译文件package.xml(manifests文件),此文件包含了描述该软件包的重要信 ...

  9. nginx反向代理架构与安装配置(一)

    这里我们准备四台虚拟机,二台负载均衡(LB01,LB02),二台web服务器(WEB01,WEB02).   这里默认所有软件都安装在/data目录下.   四台虚拟机的初始安装是centos7的最小 ...

  10. AssemblyVersion,AssemblyFileVersion解释以及获取

    简而言之,AssemblyVersion: 是程序集的版本,.NET的CLR用,用于标识出该dll的版本信息,用于定义强名称的版本号: AssemblyFileVersion: 为编译器生成的文件加入 ...